首页新闻找找看学习计划

aps.net mvc5 Forms验证问题

0
悬赏园豆:20 [已解决问题] 解决于 2015-05-13 23:40

登录时,使用 Forms验证,
string userData = UserProfileIO.Serialize(account);
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1,
account.Name,
System.DateTime.Now,
System.DateTime.Now.AddDays(30),
false,
userData,
FormsAuthentication.FormsCookiePath);

string encTicket = FormsAuthentication.Encrypt(ticket);

HttpCookie cokie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);//FormsAuthentication .FormsCookieName配置文件的cookie名称
cokie.Expires = DateTime.Now.AddDays(5);
Response.Cookies.Add(cokie);

 

但登录后,

Context.User.Identity as FormsIdentity  为空

Request.IsAuthenticated  为 false

配置   

环境 VS2013  MVC5  .net4.5
web.comfig

<authentication mode="Forms">
<forms name=".ASPXAUTH" loginUrl="~/Account" defaultUrl="~/" timeout="2880" />
</authentication>

 

Global.asax.cs :

void MvcApplication_AuthorizeRequest(object sender, EventArgs e)
{
var id = Context.User.Identity as FormsIdentity;
if (id != null && id.IsAuthenticated)
{
var roles = id.Ticket.UserData ;

}
}

 

求指教

stevenhzj的主页 stevenhzj | 初学一级 | 园豆:13
提问于:2014-05-25 21:55
< >
分享
最佳答案
0
收获园豆:10
暗香浮动 | 菜鸟二级 |园豆:361 | 2014-10-27 14:29
其他回答(1)
0

没有这句吧  FormsAuthentication.SetAuthCookie(user.UserName, RememberMe);

收获园豆:10
程序新青年 | 园豆:841 (小虾三级) | 2014-05-26 11:26
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册