【问题标题】:ASP.NET Forms Based Authentication基于 ASP.NET 表单的身份验证
【发布时间】:2011-08-21 20:07:25
【问题描述】:

我正在寻找一些关于在我的 ASP.NET 项目中实施基于表单的身份验证的指南

我有 Welcome.ASPX 页面,其中登录字段显示如下

Welcome.aspx.vb

用户输入 "LoginID" --> _LoginID.Text = "Test01"

用户输入“密码” --> _Password.Text = “Hello”

PersistForms.Checked

点击登录按钮 --> _btnLogin.Click

Protected Sub _Login_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles _Login.Click 

IF LoginID and Password MATCHES = TEUE THEN    // Comparison is done from database


FormsAuthentication.RedirectFromLoginPage(_LoginID.Text, PersistForms.Checked) 

 // Using above line it redirects to defailt webpage of my application BUT I WANT TO REDIRECT TO other then default page. How can i do this? ?? How to rediect to EmployeeInfo.ASPX page from here????


End Sub

Web Config 更新如下

<authentication mode = "Forms">

<forms

loginUrl = "Login.aspx"

name = ".ASPXFORMSAUTH" />

</authentication>

<authorization>

<deny users = "?" />

</authorization>

谢谢

【问题讨论】:

  • 为什么不使用登录控件?它很强大。

标签: asp.net forms-authentication


【解决方案1】:

您需要在 web.config 中设置 DefaultUrl。更多信息在这里:

http://msdn.microsoft.com/en-us/library/system.web.security.formsauthentication.defaulturl.aspx

所以你会做这样的事情:

<authentication mode="Forms">
  <forms loginUrl="welcome.aspx"
    defaultUrl="employeeInfo.aspx" />
</authentication>

【讨论】:

  • 如果 ReturnUrl 在查询字符串中,是否会使用 defaultUrl?即他们刚刚被从安全页面中弹出
【解决方案2】:

设置 cookie 并自己进行重定向:http://www.4guysfromrolla.com/webtech/110701-1.3.shtml

Dim cookie As HttpCookie = FormsAuthentication.GetAuthCookie (_LoginID.Text, true)
Response.Cookies.Add (cookie)
Response.Redirect ("EmployeeInfo.ASPX")  

【讨论】:

    猜你喜欢
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 2012-06-06
    • 1970-01-01
    • 1970-01-01
    • 2012-12-14
    • 2011-10-24
    相关资源
    最近更新 更多