当我们创建自己的cookie时,如何实现cookie而不是表单身份验证

时间:2011-09-29 04:37:17

标签: asp.net c#-4.0 forms-authentication security

我正在实现表单身份验证(我需要根据某些条件而不是从活动目录或数据库创建故障单)

FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1,
        "userName",
        DateTime.Now,
        DateTime.Now.AddMinutes(30), // value of time out property
        false, // Value of IsPersistent property
        String.Empty,
        FormsAuthentication.FormsCookiePath);

string encryptedTicket = FormsAuthentication.Encrypt(ticket);
HttpCookie authCookie = new HttpCookie(
                            FormsAuthentication.FormsCookieName, 
                            encryptedTicket);

authCookie.Secure = true;
Response.Cookies.Add(authCookie);

 and my web.config 


<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx"
           protection="All"
           timeout="30"
           name="test" 
           path="/"
           requireSSL="false"
           slidingExpiration="true"
          cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" />
  </authentication>
</system.web>

如果启用了浏览器cookie,则此实现正常工作。当禁用cookie时它不起作用(我尝试过Cookieless =“useuri”但它没有帮助)

请你们告诉我如何在这种情况下实施无法形式认证

我想使用uri进行身份验证cookie或任何其他更好的解决方案?

1 个答案:

答案 0 :(得分:0)

对于无cookie浏览器,asp.net提供了嵌入URL的会话ID;

见下面的问题:

What will happen to asp.net membership if the client browser is not accepting cookies