简体   繁体   English

ASP.NET成员资格提供程序,自定义登录控件

[英]ASP.NET membership provider, custom login control

I'm using the ASP.NET membership provider on my website. 我在我的网站上使用ASP.NET成员资格提供程序。 It works fine while using the Login Control in Visual Studio. 在Visual Studio中使用登录控件时,它可以正常工作。 However, I feel the Login Control has its limitation and I'm having a hard time making it fit to the design of my page. 但是,我觉得登录控件有其局限性,我很难使它适合我的页面设计。 So instead of using that Login control, I'd like to be able to just create two TextBox's and a Button myself and use that to login instead. 因此,我不想使用该Login控件,而是希望自己创建两个TextBox和一个Button并使用它来登录。 So my question is, can I create a custom login page with by creating my own textbox's and buttons? 所以我的问题是,是否可以通过创建自己的文本框和按钮来创建自定义登录页面? The code behind Login.aspx that I use with the login control right now looks like this: 我现在与登录控件一起使用的Login.aspx背后的代码如下所示:

protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
    if (Membership.ValidateUser(Login1.UserName, Login1.Password) == true)
    {
        Login1.Visible = true;
        Session["user"] = User.Identity.Name;
        FormsAuthentication.RedirectFromLoginPage(Login1.UserName, true);
    }
    else
    {
        Response.Write("Invalid Login");
    }
}

I tried changing Login1.UserName to TextBox1.Text and so on, but that didn't work. 我尝试将Login1.UserName更改为TextBox1.Text ,依此类推,但这没有用。 Any help is appreciated, thanks! 任何帮助表示赞赏,谢谢!

You should be removing Login1_Authenticate event and have a login button event to validate the credentials. 您应该删除Login1_Authenticate事件,并具有一个登录按钮事件来验证凭据。

Or depending on how you submit back to server, such as ajax calls etc. You can also use fiddler to see what's exactly being posted back to server. 或取决于您提交回服务器的方式(例如ajax调用等)。您还可以使用提琴手查看将什么确切发布回服务器。

PS. PS。 Why do not use ASP.net MVC? 为什么不使用ASP.net MVC?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM