2010-05-11 84 views
1

我试图升级我的mvc 1.0应用程序,它具有自定义的书写登录。我给你这样的authcookie:自定义身份验证不适用于asp.net 2.0

string _roles = string.Join(",", _ugr.GetUsergroupRoles(_username)); 

FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(
     1, 
     _username, 
     DateTime.Now, 
     DateTime.Now.AddHours(1), 
     false, 
     _roles, 
     "/"); 

HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket)); 
      HttpContext.Response.Cookies.Add(cookie); 

当我调试我_roles = “管理”

而且我有一个覆盖OnExecuting一个ActionFilter在那里我有:

.. 
string[] _authRoles = AuthRoles.Split(','); 

bool isAuthorized = _authRoles.Any(r => filterContext.HttpContext.User.IsInRole(r)); 

if (!isAuthorized) 
{ 
.. 

在这里,如果我调试_authRoles在其中有“Admin”,并且isAuthorized始终是false。

如果我检查“门票”它有一些:UserData =“管理员”。

那里有什么问题?它是不同的“User.IsInRole”,还是我需要在web.config中添加一些东西?

/M

回答