roleprovider

Unity dependency injection in an ASP MVC 5.0 RoleProvider defined in configuration

筅森魡賤 提交于 2019-12-25 02:09:38
问题 I'm trying to implement a role provider using a separate EF repository class, as an injectable dependency, to access my roles store. My problem is that the role provider is defined in configuration (web.config) and therefore is not instantiated via the Unity DI container. I haven't been able to find a way to either shift the configuration to code or get hold of the role provider after it's built to call container.BuildUP() on it. Any suggestions would be appreciated. 回答1: I think that my

ASP.NET MVC 3 Dropdownlist of Users

梦想的初衷 提交于 2019-12-24 10:55:30
问题 In my application I have associated my UserId to a table in my database. I need that when I create a new item I can choose the user name from a dropdownlist. And 'possible to do this with the element viewbag? @Html.EditorFor(model => model.UserId) I use default membership provider so I can't use Entity Framework for this problem EDIT EDIT 2 This is my action create: [HttpPost] public ActionResult Create(Employe employe) { var users = Roles.GetUsersInRole("Admin"); SelectList list = new

Custom RoleProvider using session

末鹿安然 提交于 2019-12-23 20:23:19
问题 I was considering using the custom MembershipProvider / RoleProviders. Unfortunately, the security layer we currently have requires some session stuff being set. So, when the IsUserInRole() method is called, the Session object is always null, due to the Session stuff being all prepopulated. Any suggestions on how I would be able to work around this, and retain the use of the Session based security model we have? (I didn't write it, and I have got to use it). Any help greatly appreciated as

Custom RoleProvider Not Called

岁酱吖の 提交于 2019-12-23 17:30:28
问题 My application has custom Role and MembershipProviders. I've registered them in web.config, but when I try to do if(User.IsInRole("Blah")) , neither of my breakpoints in the RoleProvider's Initialize or IsUserInRole are hit. The membership provider works fine, so I guess there must be something I've missed from web.config. This is what I have: <system.web> ... <membership defaultProvider="MyAppMembershipProvider" userIsOnlineTimeWindow="15"> <providers> <clear /> <add name=

How to make RavenDB DocumentStore available to calling APIs

◇◆丶佛笑我妖孽 提交于 2019-12-23 04:53:25
问题 I have an MVC4 application using RavenDB as a datastore. The application has MVC/Web, Domain, Data, and Security layers. I am writing custom membership and role providers that need to initialize the database and access the DocumentStore. I'm writing these class from the Security layer, and would like to use a singleton DocumentStore (set in the application), but I can't figure out how to access it. Other, examples I see of writing custom providers for RavenDB create new DocumentStore

Reference current RoleProvider instance?

我怕爱的太早我们不能终老 提交于 2019-12-22 01:26:56
问题 When inside an ASP.NET page, module or handler with an HttpContext present, how do I get a reference to the current RoleProvider instance? It's the provider used for authorization when the IPrincipal.IsInRole(..) method is called. By default, or from configuration, my provider seems to be a SqlRoleProvider instance by an error given when I'm running the app. I want to inspect the type of provider at runtime to provide feedback on which one is actually being used. 回答1: The static Roles class

Does the asp.net RoleManager really cache the roles for a user in a cookie if so configured?

本小妞迷上赌 提交于 2019-12-21 20:52:52
问题 In my web.config I have the Role Manager configured as follows: <roleManager enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All"> however in our custom RoleProvider it would seems that the GetRolesForUser method is always being called, rather than as I would have expected, the RoleManager serving up the roles from its cookie. We're using something like to get the roles

Get permission from Authorize Attribute?

安稳与你 提交于 2019-12-19 09:19:38
问题 I've implemented my own Authorize attribute, and I notice that it queries to check permissions when I use [Authorize] . Is there any way I can get that permission and use it in the current controller that applies the Authorize attribute without having to rewrite and requery the code in the controller? 回答1: Yes, you can. If you implemented your Authorize attribute as an ActionFilterAttribute you can use the ViewData collection to store information like this : public class

Override the User.IsInRole and [Authorize(Roles = “Admin”)] for MVC4 application

旧城冷巷雨未停 提交于 2019-12-18 13:54:12
问题 I have created a custom role provider for my MVC4 application where I have been successfully able to override CreateRole, GetAllRoles and RoleExists methods and link them to my existing database as follows: namespace Project.Providers { public class MyProvider : System.Web.Security.SqlRoleProvider { private MyContext dbcontext = new MyContext(System.Configuration.ConfigurationManager.ConnectionStrings["MyContext"].ConnectionString); private Repository<MyUser> userRepository; private

Authorization using active directory role provider MVC4

笑着哭i 提交于 2019-12-18 12:17:32
问题 I'm building a MVC4 application for internal use in a corporate enviroment. I use windows authentication, which works fine, but I'm having troubles using Active Directory groups as roles for authorization. My Web.config looks like this: <authentication mode="Windows" /> <roleManager enabled="true" defaultProvider="AspNetWindowsTokenRoleProvider"> <providers> <clear /> <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" /> <