views:

30

answers:

1

Hello

I'm trying to upgrade my mvc 1.0 application that had a custom written login. I assign the authcookie like this:

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);

When I debug I got _roles = "Admin"

And I have an actionfilter that overrides OnExecuting where I have:

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

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

if (!isAuthorized)
{
 ..

And here if I debug _authRoles has "Admin" in it, and isAuthorized is always false.

If I check the "ticket" it has some: UserData = "Admin".

What can be wrong there? Is it the "User.IsInRole" that is different, or do I need to add something in web.config?

/M