roleprovider

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

此生再无相见时 提交于 2019-11-30 10:27:56
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 Repository<Role> roleRepository; public MyProvider() { this.userRepository = new Repository<MyUser>(dbcontext);

Authorization using active directory role provider MVC4

半腔热情 提交于 2019-11-30 06:44:18
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="/" /> </providers> </roleManager> <authorization> <deny users="?" /> </authorization> When I use User authorization

ASP.NET MVC 3 Ninject Custom Membership and Role Provider

落爺英雄遲暮 提交于 2019-11-30 04:51:08
问题 Hi i got some problems enabling custom Membership and Role Provider, i got following error: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. System.InvalidOperationException: Default Membership Provider could not be found. It's pointing to my mvc3.ninject kernel.Inject(Membership.Provider) My MVC3.Ninject in app_start: private static void RegisterServices

Remove asp.net membership and roles provider

主宰稳场 提交于 2019-11-30 00:17:36
问题 For whatever reason, the site I was working on (after a bit of pause) begun screaming about an sql server connection for the asp.net membership. I'm using mysql without asp.net membership so it was weird. However just to be sure I've decided to remove anything related to it, including role providers. I've added these to the web.config <membership> <providers> <clear /> </providers> </membership> <roleManager enabled="false"> <providers> <clear /> </providers> </roleManager> <profile enabled=

ASP.NET MVC redirect to an access denied page using a custom role provider

点点圈 提交于 2019-11-29 18:46:05
I'm creating a custom role provider and I set a Authorize attribute specifying a role in my controller and it's working just fine, like this: [Authorize(Roles="SuperAdmin")] public class SuperAdminController : Controller ... But when an user doens't have access to this controller, he's redirected to login page. How can I redirect him to a "AcessDenied.aspx" page? [AccessDeniedAuthorize(Roles="SuperAdmin")] public class SuperAdminController : Controller AccessDeniedAuthorizeAttribute.cs: public class AccessDeniedAuthorizeAttribute : AuthorizeAttribute { public override void OnAuthorization

What could cause many data access exceptions using EF code first in a custom RoleProvider?

十年热恋 提交于 2019-11-29 16:20:19
My role provider looks like the class below (abridged). I am running on IIS Express, and SQL 2012 Express, from VS 2012, and I get a multitude of seemingly random exceptions in this role provider code. public class Educ8RoleProvider : RoleProvider { private readonly Educ8DbContext _dbContext = new Educ8DbContext(); private readonly Authorization _authorization; public Educ8RoleProvider() { _authorization = new Authorization(_dbContext); } public override void Initialize(string name, System.Collections.Specialized.NameValueCollection config) { try { base.Initialize(name, config); } catch

ASP.NET Multi tenant application with tenant specific roles

隐身守侯 提交于 2019-11-29 05:19:40
We have a multi-tenant ASP.NET application. So far tenants have been isolated from each other, however now we have Agencies that manage multiple tenants and want to be able to manage all their tenants with a single user account. I'm trying to figure out the best way to accomplish that, hopefully without much change to the existing technologies that we are using. Relevant technical details: AspNetSqlMembershipProvider for both membership and roles C# 4.0 (soon to be 4.5) Forms Authentication Both aspx and MVC (v3) pages Assume 100 or more tenants, so any solution needs to support that I believe

Poor Performance with WindowsTokenRoleProvider

老子叫甜甜 提交于 2019-11-29 02:03:58
I'm using WindowsTokenRoleProvide r to determine Active Directory group membership in an ASP.NET web application. My problem is that performance is not good, especially when a user is in many groups. As an example, I am in 253(!) groups, and WindowsTokenRoleProvider is taking around 150 seconds to determine what groups I am in. I know I can use caching so that this isn't done on subsequent requests for a user, but obviously it isn't acceptable to take that long on the first hit. What are my options? Can I force WindowsTokenRoleProvider to only consider certain groups? (I'm only interested in 5

MVC4: UserIsInRole - Unable to connect to SQL Server database

◇◆丶佛笑我妖孽 提交于 2019-11-28 18:54:39
Breaking my head around with this, yesterday it worked fine and today it seems to be broken: This line is generating the error: @if (Roles.IsUserInRole(HttpContext.Current.User.Identity.Name, "Admin")) the error is: Unable to connect to SQL Server database. Whole exception: System.Web.HttpException was unhandled by user code HResult=-2147467259 Message=Unable to connect to SQL Server database. Source=System.Web ErrorCode=-2147467259 WebEventCode=0 StackTrace: at System.Web.DataAccess.SqlConnectionHelper.CreateMdfFile(String fullFileName, String dataDir, String connectionString) at System.Web

Specifying Roles in web.config of an asp.net MVC application

三世轮回 提交于 2019-11-28 06:53:37
I am creating an MVC application with forms auth. I am authenticating against active directory and so have created a custom RoleProvider. My application is only concerned with a small set of roles which up until now I have been defining in the appSettings section of my web.config: <appSettings> <add key="DirectorRole" value="Domain\Directors" /> <add key="ManagementRole" value="Domain\Managers" /> ... </appSettings> However I have run into a couple of problems with this approach: I cannot reference these setting in my contoller data annotations: [Authorize(Roles = ConfigurationManager