我有这个Action方法,我使用Authorize with Roles,如:
[HttpGet]
[Authorize(Roles = "member")]
public virtual ActionResult Profile()
{
...
}
我有这个方法登录并添加cooki:
SetAuthCookie(loginVM.UserName, RoleOfTheMember.Name, loginVM.RememberMe);
RoleOfTheMember.Name有值:"会员"
这个SetAutoCooki:
private void SetAuthCookie(string memberName, string roleofMember, bool presistantCookie)
{
var timeout = presistantCookie ? FormsAuthentication.Timeout.TotalMinutes : 30;
var now = DateTime.UtcNow.ToLocalTime();
var expirationTimeSapne = TimeSpan.FromMinutes(timeout);
var authTicket = new FormsAuthenticationTicket(
1,memberName,now,now.Add(expirationTimeSapne),presistantCookie,roleofMember,FormsAuthentication.FormsCookiePath
);
var encryptedTicket = FormsAuthentication.Encrypt(authTicket);
var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket)
{
HttpOnly = true,
Secure = FormsAuthentication.RequireSSL,
Path = FormsAuthentication.FormsCookiePath
};
if (FormsAuthentication.CookieDomain != null)
{
authCookie.Domain = FormsAuthentication.CookieDomain;
}
if (presistantCookie)
authCookie.Expires = DateTime.Now.AddMinutes(timeout);
Response.Cookies.Add(authCookie);
}
但是当调用此操作时,我通过浏览器获得此错误:
The page isn't redirecting properly
什么是问题?
我没有使用任何RoleProvider。我是否使用了工具角色提供程序?