且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

登录控件的登录事件未触发

更新时间:2023-12-04 08:54:40

有许多帖子描述了如何为 SharePoint 2010 创建您自己的自定义登录页面.这里是我关注的.通常,他们创建一个继承自 FormsSignInPage 的应用程序页面.对于只需要更改外观的页面,这很有效.在某些情况下,例如这种情况,以这种方式创建登录页面可能还不够.

There are number of posts that describe how to create your own custom login page for SharePoint 2010. Here is the one I followed. In general, they create an application page that inherits from FormsSignInPage. For a page that just needs to change the look and feel, this works well. In some cases, like this one, creating the login page in this way may not be enough.

在本post,您需要继承自 IdentityModelSignInPageBase 而不是 FormsSignInPage.您还需要为身份验证事件创建一个事件处理程序,并将其注册到页面的 OnLoad 事件中.

The way it is described at the end of this post, you need to inherit from IdentityModelSignInPageBase instead of FormsSignInPage. You also need to create an event handler for the authenticate event and register this in the OnLoad event of the page.

这是因为控件中的 Authenticate 方法会在调用 OnLoggedIn 事件之前自动将用户带到ReturnUrl"页面.这种方法只需要两行代码就可以验证用户.

This is because the Authenticate method in the control will automatically take the user to the "ReturnUrl" page before it ever calls the OnLoggedIn event. It only takes two lines of code to authenticate the user in this method.

void signInControl_Authenticate(object sender, AuthenticateEventArgs e)
{
  Login signInControl = sender as Login;
  e.Authenticated = SPClaimsUtility.AuthenticateFormsUser(this.Page.Request.Url, signInControl.UserName, signInControl.Password);
}

由于您的代码现在不会将用户发送到 ReturnUrl 值,因此已到达 OnLoggedIn 事件.

Since your code now does not send the user to the ReturnUrl value, the OnLoggedIn event is reached.

如果我必须创建自定义 Authenticate 方法,您可能会问为什么我需要 OnLoggedIn 事件.好吧,控件仍然会为您处理一些功能.例如,如果用户未进行身份验证(即错误的 UN 和 PW 组合),控件将显示错误消息并且 OnLoggedIn 永远不会触发.

You may ask why do I need the OnLoggedIn event if I have to create a custom Authenticate method. Well, there are still functions the control will handle for you. For instance, if the user does not authenticate (ie bad UN and PW combination), the control will display the error message and the OnLoggedIn never fires.