如何使用窗体身份验证,而不登录控制? [英] How to use forms authentication without login control?

本文介绍了如何使用窗体身份验证,而不登录控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用窗体身份验证登录不control.I不希望使用asp.net登录控制在我的site.But我要实现窗体身份验证,并在我的数据库来验证用户。

How to use forms authentication without login control.I don't want to use asp.net login control in my site.But i have to implement forms authentication and to validate users in my database.

推荐答案

我假设,而不是使用一个登录控件,您使用的是一些文本框(如用户名/密码),登录按钮。在code可能是这个样子:

I am assuming that instead of using a login control, you are using a few textboxes(eg username/password) and a logon button. The code could look something like this:

在你的aspx文件

<asp:Textbox runat="server" ID="Username"/>
<asp:Textbox runat="server" ID="Password"/>
<asp:Button runat="server" ID="Login" OnClick="Login_OnClick"/>

<asp:Label runat="server" ID="Msg" >

和服务器端:

public void Login_OnClick(object sender, EventArgs args)
{
if (Membership.ValidateUser(Username.Text,Password.Text))
{
     FormsAuthentication.RedirectFromLoginPage(Username.Text,
     NotPublicCheckBox.Checked);
}
else
Msg.Text = "Login failed.";
}

窗体身份验证通常由两部分组成:

The forms authentication usually consists of 2 parts:


  • 调用API会员认证/验证用户

  • 使用FormsAuthentication API登录(创建AUTH饼干等)
  • 用户

有关更多信息看看这些文章:

For more info look at these articles:

  • http://msdn.microsoft.com/en-us/library/aa480476.aspx
  • http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.redirectfromloginpage.aspx
  • http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.authenticate.aspx

这篇关于如何使用窗体身份验证,而不登录控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆