关于Forms Authentication的问题请教

aleckz 2001-11-29 06:09:24
在web application中使用forms authentication,当客户端被重定向到
登录页面后,根据SDK中的例子,收集了用户名与密码并作了必要的验证
之后,使用FormsAuthentication.RedirectFromLoginPage方法将客户
送到原先访问的页面。在此过程中,系统隐含地创建了一个GenericPrincipal
对象。
我想问的是,如何在验证后,指定该用户的role呢?
如果不能指定用户的role,那么在web.config文件中,就无法根据roles来做
authorization了。
如果直接创建一个new GenericPrincipal并指定role,那么如何将其返回到
客户端呢?
我翻遍了SDK也没有找到相关的解释,请大家指教!
...全文
57 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
aleckz 2001-12-04
  • 打赏
  • 举报
回复
我想知道可不可以根据不同的location指定不同的login page?
acptvb 2001-12-03
  • 打赏
  • 举报
回复
感谢您使用微软产品。

您可以在Application_AuthenticateRequest事件中加入类似以下代码:
protected void Application_AuthenticateRequest(Object sender, EventArgs e)
{
if (HttpContext.Current.User != null)
{
if (HttpContext.Current.User.Identity.AuthenticationType == "Forms" )
{
System.Web.Security.FormsIdentity id = (System.Web.Security.FormsIdentity)HttpContext.Current.User.Identity;
if (id.Name == "username")
{
String[] myRoles = new String[2];
myRoles[0]= "managers";
myRoles[1]= "developers";
HttpContext.Current.User = new System.Security.Principal.GenericPrincipal(id,myRoles);
}
}
}
}

- 微软全球技术中心 VB技术支持

本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。

1,978

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧