[英]LoginUser_Authenticate and LoggingIn events won't fire
I'm currently developing a website that uses FormAuthentication to log in a user against an ActiveDirectory Domain. 我目前正在开发一个使用FormAuthentication根据ActiveDirectory域登录用户的网站。 I need to create a login form to handle the user credentials since they must be able to log into multiple domains regardless of the local user pc domain.
我需要创建一个登录表单来处理用户凭据,因为他们必须能够登录到多个域,而不管本地用户pc域。
I figured I would use the Login WebControl. 我想我会使用Login WebControl。 My problem is that neither Authenticate nor LoggingIn events fire when the user logs in.
我的问题是,当用户登录时,Authenticate和LoggingIn事件都不会触发。
Here is my aspx login page: 这是我的aspx登录页面:
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Logon.aspx.cs" Inherits="WebSite1.Logon1" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.9.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<p>
Por favor ingrese usuario y contraseña.
</p>
<asp:Login ID="LoginUser" runat="server"
RenderOuterTable="false" RememberMeSet="true" FailureText="El usuario/contraseña no es correcto, por favor intente nuevamente"
OnAuthenticate="LoginUser_Authenticate" OnLoggingIn="LoginUser_LoggingIn">
<LayoutTemplate>
<span class="failureNotification">
<asp:Literal ID="FailureText" runat="server"></asp:Literal>
</span>
<dx:ASPxValidationSummary ID="LoginUserValidationSummary" runat="server" CssClass="failureNotification" ValidationGroup="LoginUserValidationGroup">
</dx:ASPxValidationSummary>
<div class="accountInfo">
<fieldset class="login">
<legend>Información de cuenta</legend>
<p>
<dx:ASPxLabel ID="DomainLabel" runat="server" Text="Dominio:" AssociatedControlID="Domain">
</dx:ASPxLabel>
<dx:ASPxComboBox ID="Domain" runat="server" Width="250px">
</dx:ASPxComboBox>
<asp:RequiredFieldValidator ID="DomainRequired" runat="server" ControlToValidate="Domain"
CssClass="failureNotification" ErrorMessage="El dominio es requerido." ToolTip="El dominio es requerido."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<dx:ASPxLabel ID="UserNameLabel" runat="server" Text="Usuario:" AssociatedControlID="UserName">
</dx:ASPxLabel>
<dx:ASPxTextBox ID="UserName" runat="server" CssClass="textEntry" Width="250px">
</dx:ASPxTextBox>
<asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
CssClass="failureNotification" ErrorMessage="El nombre de usuario es requerido." ToolTip="El nombre de usuario es requerido."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<dx:ASPxLabel ID="PasswordLabel" runat="server" Text="Contraseña:" AssociatedControlID="Password">
</dx:ASPxLabel>
<dx:ASPxTextBox ID="Password" runat="server" CssClass="passwordEntry" Width="250px" Password="True">
</dx:ASPxTextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
CssClass="failureNotification" ErrorMessage="La contraseña es requerida." ToolTip="La contraseña es requerida."
ValidationGroup="LoginUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<dx:ASPxCheckBox ID="RememberMe" runat="server">
</dx:ASPxCheckBox>
<dx:ASPxLabel ID="RememberMeLabel" runat="server" Text="Mantener sesión iniciada" AssociatedControlID="chkRememberMe" CssClass="inline">
</dx:ASPxLabel>
</p>
</fieldset>
<dx:ASPxButton ID="LoginButton" runat="server" Text="Iniciar sesión" ValidationGroup="LoginUserValidationGroup">
</dx:ASPxButton>
</div>
</LayoutTemplate>
</asp:Login>
</asp:Content>
As you can see, OnAuthenticate="LoginUser_Authenticate" OnLoggingIn="LoginUser_LoggingIn"
are set in the login control properties. 如您所见,
OnAuthenticate="LoginUser_Authenticate" OnLoggingIn="LoginUser_LoggingIn"
在登录控件属性中设置。 I defined both methods on code behind and set breakpoints. 我在后面的代码上定义了两种方法并设置了断点。 The page is doing a postback since it gets refreshed, but the events never get called.
该页面正在进行回发,因为它被刷新,但事件永远不会被调用。
I've already checked for AutoEventWireup="true"
, and web.config is configured to use this form for login: 我已经检查了
AutoEventWireup="true"
,并且web.config配置为使用此表单进行登录:
<authentication mode="Forms"> <forms loginUrl="logon.aspx" name="adAuthCookie" timeout="10" path="/"> </forms>
Can anyone suggest what to look for to find what might be wrong? 任何人都可以建议找什么找到可能出错的地方?
As requested here is my code behind class: 这里要求的是我的课程代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DevExpress.Web.ASPxEditors;
namespace WebSite1
{
public partial class Logon1 : System.Web.UI.Page
{
protected ASPxComboBox Domain;
protected void Page_Load(object sender, EventArgs e)
{
Domain = LoginUser.FindControl("Domain") as ASPxComboBox;
Domain.Items.Clear();
String allowedDomains = System.Web.Configuration.WebConfigurationManager.AppSettings["AllowedDomains"];
List<string> allowedDomainsList = allowedDomains.Split('|').ToList<string>();
foreach (string allowedDomain in allowedDomainsList)
{
Domain.Items.Add(allowedDomain, allowedDomain);
}
Domain.SelectedIndex = 0;
}
protected void LoginUser_LoggingIn(object sender, LoginCancelEventArgs e)
{
}
protected void LoginUser_Authenticate(object sender, AuthenticateEventArgs e)
{
}
}
}
Changed public partial class Login1 : System.Web.UI.Page
to public partial class Login : System.Web.UI.Page
将
public partial class Login1 : System.Web.UI.Page
更改为public partial class Login : System.Web.UI.Page
And CodeBehind="Logon.aspx.cs" Inherits="WebSite1.Logon1"
to CodeBehind="Logon.aspx.cs" Inherits="WebSite1.Logon"
CodeBehind="Logon.aspx.cs" Inherits="WebSite1.Logon1"
to CodeBehind="Logon.aspx.cs" Inherits="WebSite1.Logon"
No changes in behaviour so far. 到目前为止,行为没有变化。
I found this link Customizing the Appearance of ASP.NET Login Controls that explains that I need to catch the command event of my Login Button. 我找到了这个链接自定义ASP.NET登录控件的外观 ,解释了我需要捕获我的登录按钮的命令事件。 So I implemented this method:
所以我实现了这个方法:
protected void LoginButton_Command(object sender, CommandEventArgs e)
{
switch (e.CommandName)
{
case "LogginIn":
LoginUser_LoggingIn(sender, e);
break;
}
}
My problem now is that I don't know how to call the LogginIn event since e
is a CommandEventArgs
and I need a LoginCancelEventArgs
. 我现在的问题是我不知道如何调用LogginIn事件,因为
e
是一个CommandEventArgs
,我需要一个LoginCancelEventArgs
。
According to what you've written your public partial class name and your Inherits attribute still don't match. 根据您编写的内容,您的公共部分类名称和Inherits属性仍然不匹配。
Inherits="WebSite1.Logon"
but 但
public partial class Login : System.Web.UI.Page
Shouldn't both be either Login or Logon? 不应该同时登录或登录?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.