首页 > 其他 > 详细

Form authentication(表单认证)问题

时间:2016-05-11 14:50:44      阅读:187      评论:0      收藏:0      [点我收藏+]

前言

最近在做ASP.NET MVC中表单认证时出了一些问题,特此记录。

问题

进行表单认证时,在 PostAuthenticateRequest 事件中从Cookie值中解密票据。如下:

        protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
        {
            var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            if (authCookie != null)
            {

                var authTicket = FormsAuthentication.Decrypt(authCookie.Value);
                TODO......
             }
         }        

昨天一点问题都没有,今天再次运行却意外出现如下结果:

技术分享

此问题从未遇见过,只能求助于stackoverflow了。

最终发现需要在配置文件中添加认证方式:

   <authentication mode="Forms">
      
   </authentication>

如上设置即可解决问题。

总结

上述加密和解密 FormsAuthentication.Encrypt and Decrypt 也和  machine key 有关,如上述未解决可通过设置machine key来解决。

参考网址:

formsauthentication unable to validate data

Configure MachineKey

 

Form authentication(表单认证)问题

原文:http://www.cnblogs.com/CreateMyself/p/5481631.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!