ASP.NET Forms身份验证和成员身份 [英] ASP.NET FormsAuthentication and membership
问题描述
我可以在没有成员资格的情况下在ASP.NET中使用表单身份验证. 即:
I can use forms authentication in ASP.NET without membership. i.e:
FormsAuthentication.RedirectFromLoginPage(usuario.UsuDs, false);//usuario.UsuDS is the textbox username in login's form
然后我可以编写如下代码:
Then i can write code like:
[Authorize(User="UserTest")]
public ActionResult Criar(Usuarios usuario)
{
try
{
...
}
...
}
它仅在特定视图中授权"UserTest"用户. 但是,我想写:
And it only authorize "UserTest" user in especific views. However,i would like to write:
[Authorize(Roles="Admin")]
public ActionResult Criar(Usuarios usuario)
{
try
{
...
}
...
}
但是我不能设置没有会员资格的角色.
But i cant set roles without Membership.
是否有任何想法可以在没有成员资格的情况下从ASP.NET设置和获取角色?
Any ideias to set and get roles from ASP.NET without membership?
推荐答案
您当然可以使用没有成员资格的角色.实际上,在ASP.NET 2.0之前,garsh darnit根本没有成员资格,所以我们很喜欢这种方式! ;-)
You can certainly use roles without Membership. In fact, prior to ASP.NET 2.0 we didn't have Membership at all, garsh darnit, and we liked it that way!! ;-)
这里有一篇文章,展示了如何在没有成员资格的情况下实现角色:基于角色的授权方式表单身份验证.简而言之,您必须编写一些代码,以在角色通过身份验证后将其分配给用户.
Here's an article that shows how to implement roles without Membership: Role-Based Authorization With Forms Authentication. In a nutshell, you have to write some code that assigns the roles to the user once they're authenticated.
编程愉快!
这篇关于ASP.NET Forms身份验证和成员身份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!