自定义身份验证不适用于 asp.net 2.0
我正在尝试升级具有自定义写入登录名的 mvc 1.0 应用程序。我这样分配 authcookie:
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 =“Admin”
我有一个动作过滤器,它覆盖了我所拥有的 OnExecuting:
..
string[] _authRoles = AuthRoles.Split(',');
bool isAuthorized = _authRoles.Any(r => filterContext.HttpContext.User.IsInRole(r));
if (!isAuthorized)
{
..
在这里,如果我调试 _authRoles 其中有“Admin”,并且 isAuthorized 始终为 false。
如果我检查“票”,它有一些:UserData =“Admin”。
那里可能出什么问题了?是“User.IsInRole”不同,还是我需要在 web.config 中添加一些内容?
/米
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
http://www. Eggheadcafe.com/tutorials/aspnet/009e2e5e-5a44-4050-8233-59a0d69844e8/basics-forms-authenticat.aspx
http://www.eggheadcafe.com/tutorials/aspnet/009e2e5e-5a44-4050-8233-59a0d69844e8/basics-forms-authenticat.aspx