web.config表单身份验证,cookiename

时间:2012-11-28 06:09:33

标签: asp.net

我有一个带有以下内容的web.config:

 <system.web>
<customErrors mode="Off"/>

<authentication mode="Forms">
  <forms loginUrl="Login.aspx" name="SIPE_ASPXAUTH">
    <credentials passwordFormat="Clear">
      <user name="user1" password="123456"/>
      <user name="user2" password="123456"/>
      <user name="user3" password="123456"/>
    </credentials>

  </forms>

</authentication>


<authorization>

  <deny users="?"/>
</authorization>
<compilation debug="true"/>

此web.config始终将我重定向到以下网址

http://localhost:53077/Login.aspx?ReturnUrl=%2fDefault.aspx

我的开始页面是Login.aspx,即使在输入正确的凭证后,它也会将我重定向到上面的网址。

所以这就是我所做的。 我在

中取出了name属性
 <forms loginUrl="Login.aspx">

并保持其他一切不受影响。 它运作得很好。

任何人都可以解释原因。 我知道这是一个cookiename,默认是ASPXAUTH。此cookie用于验证用户身份。它也存储在tools..options ...

设置此cookiename有什么用。是否允许跨浏览器functinality.n 如何通过在<forms loginUrl="Login.aspx">

中使用name属性来使其工作

谢谢你

1 个答案:

答案 0 :(得分:0)

配置设置似乎没问题,但是您在登录页面中编写了一些代码,其代码也用于表单身份验证。检查用户名和&amp;密码是正确的你必须写下面的代码:

FormsAuthentication.SetAuthCookie(
                 this.TextBox_username.Text.Trim(), flase);

         FormsAuthenticationTicket ticket1 = 
            new FormsAuthenticationTicket(
                 1,                                   // version
                 this.TextBox_username.Text.Trim(),   // get username  from the form
                 DateTime.Now,                        // issue time is now
                 DateTime.Now.AddMinutes(10),         // expires in 10 minutes
                 false,      // cookie is not persistent
                 "HR"                              // role assignment is stored
                 // in userData
                 );
          HttpCookie cookie1 = new HttpCookie(
            FormsAuthentication.FormsCookieName, 
            FormsAuthentication.Encrypt(ticket1) );
          Response.Cookies.Add(cookie1);

有关表单身份验证Click Here

的更多详细信息