roles

asp.net identity get all roles of logged in user

故事扮演 提交于 2019-11-26 21:58:06
I created a role based menu for which I followed this tutorial. Some where down that page you'll see this line of code: String[] roles = Roles.GetRolesForUser(); It returns all roles of the currently logged in user. I was wondering how to accomplish this with the new ASP.NET Identity system? It's still pretty new and there is not much to find about it. Controller.User.Identity is a ClaimsIdentity . You can get a list of roles by inspecting the claims... var roles = ((ClaimsIdentity)User.Identity).Claims .Where(c => c.Type == ClaimTypes.Role) .Select(c => c.Value); --- update --- Breaking it

asp.net mvc decorate [Authorize()] with multiple enums

余生颓废 提交于 2019-11-26 21:39:50
I have a controller and I want two roles to be able to access it. 1-admin OR 2-moderator I know you can do [Authorize(Roles="admin, moderators")] but I have my roles in an enum. With the enum I can only authorize ONE role. I can't figure out how to authorize two. I have tried something like [Authorize(Roles=MyEnum.Admin, MyEnum.Moderator)] but that wont compile. Someone once suggested this: [Authorize(Roles=MyEnum.Admin)] [Authorize(MyEnum.Moderator)] public ActionResult myAction() { } but it doesn't work as an OR. I think in this case the user has to be part of BOTH roles. Am I overlooking

Role based authentication in the new MVC 4 Internet template using simplemembership

我的梦境 提交于 2019-11-26 19:27:07
I like the new simplemembership feature in MVC 4 internet template with links to OAuth for external logins in VS 2012 RTM. For the most part authentication feature are working. However even after spending over 8 hours on this I am unable to implement roles based authorization to work on my controllers. SimpleMembership is turning out to be anything but simple. I have searched stackoverflow, googled and have read the latest by John Galloway , tried many suggestions and still have not been able to resovle this issue. It all started with getting Sql connection error and could not figure out why

How do I serve up an Unauthorized page when a user is not in the Authorized Roles?

微笑、不失礼 提交于 2019-11-26 19:11:33
问题 I am using the Authorize attribute like this: [Authorize (Roles="Admin, User")] Public ActionResult Index(int id) { // blah } When a user is not in the specified roles, I get an error page (resource not found). So I put the HandleError attribute in also. [Authorize (Roles="Admin, User"), HandleError] Public ActionResult Index(int id) { // blah } Now it goes to the Login page, if the user is not in the specified roles. How do I get it to go to an Unauthorized page instead of the login page,

How can I create a view that has different displays according to the role the user is in?

孤街浪徒 提交于 2019-11-26 18:59:50
问题 I want to create a view that has different displays according to the role the user is in. Should I create a different view for different roles or should I check the roles on the Veiw page itself rather than in the actions? How would I check the role on the view page? 回答1: Or should i use check the roles on the Veiw page its self rather than on actions, if so can someone plz show me how do check that on view page You need to do both. Check roles on actions as a security measure and check roles

Grant all on a specific schema in the db to a group role in PostgreSQL

喜欢而已 提交于 2019-11-26 18:30:16
Using PostgreSQL 9.0, I have a group role called "staff" and would like to grant all (or certain) privileges to this role on tables in a particular schema. None of the following work GRANT ALL ON SCHEMA foo TO staff; GRANT ALL ON DATABASE mydb TO staff; Members of "staff" are still unable to SELECT or UPDATE on the individual tables in the schema "foo" or (in the case of the second command) to any table in the database unless I grant all on that specific table. What can I do make my and my users' lives easier? Update: Figured it out with the help of a similar question on serverfault.com .

Can I hide/show asp:Menu items based on role?

为君一笑 提交于 2019-11-26 18:05:55
问题 Am I able to hide certain menu items in an asp:Menu control based on role? <asp:Menu ID="mTopMenu" runat="server" Orientation="Horizontal" /> <Items> <asp:MenuItem Text="File"> <asp:MenuItem Text="New Project" /> <asp:MenuItem Text="Release Template" NavigateUrl="~/Release/ReleaseTemplate.aspx" /> <asp:MenuItem Text="Release Schedule" NavigateUrl="~/Release/ReleaseSchedule.aspx" /> <asp:MenuItem Text="Roles" NavigateUrl="~/Admin/AdminRoles.aspx" /> </asp:MenuItem> </Items> </asp:Menu> How can

Allow multiple roles to access controller action

老子叫甜甜 提交于 2019-11-26 11:46:39
问题 Right now I decorate a method like this to allow \"members\" to access my controller action [Authorize(Roles=\"members\")] How do I allow more than one role? For example the following does not work but it shows what I am trying to do (allow \"members\" and \"admin\" access): [Authorize(Roles=\"members\", \"admin\")] 回答1: Another option is to use a single authorize filter as you posted but remove the inner quotations. [Authorize(Roles="members, admin")] 回答2: If you want use custom roles, you

asp.net identity get all roles of logged in user

大城市里の小女人 提交于 2019-11-26 09:07:15
问题 I created a role based menu for which I followed this tutorial. Some where down that page you\'ll see this line of code: String[] roles = Roles.GetRolesForUser(); It returns all roles of the currently logged in user. I was wondering how to accomplish this with the new ASP.NET Identity system? It\'s still pretty new and there is not much to find about it. 回答1: Controller.User.Identity is a ClaimsIdentity . You can get a list of roles by inspecting the claims... var roles = ((ClaimsIdentity

asp.net mvc decorate [Authorize()] with multiple enums

北战南征 提交于 2019-11-26 07:59:29
问题 I have a controller and I want two roles to be able to access it. 1-admin OR 2-moderator I know you can do [Authorize(Roles=\"admin, moderators\")] but I have my roles in an enum. With the enum I can only authorize ONE role. I can\'t figure out how to authorize two. I have tried something like [Authorize(Roles=MyEnum.Admin, MyEnum.Moderator)] but that wont compile. Someone once suggested this: [Authorize(Roles=MyEnum.Admin)] [Authorize(MyEnum.Moderator)] public ActionResult myAction() { } but