简体   繁体   中英

SimpleMembership WebForms Asp.net 4.0 roles

I am trying to find a way to manage roles for an existing WebForms ASP.NET 4.0) application. This is not MVC. I cannot change the existing project to MVC nor .NET 4.5, so please provide solutions given my requirements.

I was looking at SimpleMembership as a possible way to manage roles without having to install the whole membership (aspnet_regsql.exe) with tables that I don't need.

This is an intranet site. Users will be authenticated via their windows identity, so there is no login per se . Most users will not be in any user database, and I want to control roles so that if they are not specifically provided additional roles, they still have access (perhaps a public role, or simple no role).

For the users that will be in a database, I want to be able to assign roles (Admin, Manager, etc) so that they have greater access to various pages and features. A user could have no role (or public, as mentioned above) or have a single role or multiple roles.

So, is it possible? Can I have a role based system for only those users that are in a table and make everyone else access parts of the site without having to login?

There is an existing table of users in SQL Server. I should be able to use this, not a text file / xml / manual approach. An admin page will be created to assign roles to users and add users.

It seems that I should be able to use SimpleMembership according to this: http://blog.osbornm.com/2010/07/21/using-simplemembership-with-asp-net-webpages/

Though it says that I need to add _start.cshtml with some MVC code, this will be fine as long as I don't need to convert the whole site to MVC.

Currently, I am getting an error with this:

The type 'WebMatrix.WebData.WebSecurity' exists in both 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\WebMatrix.WebData\v4.0_1.0.0.0__31bf3856ad364e35\WebMatrix.WebData.dll' and 'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\WebMatrix.WebData\v4.0_2.0.0.0__31bf3856ad364e35\WebMatrix.WebData.dll' 

I think that once I fix this, most likely a web.config setting, that I should be fine.

It turns out that all I had to do to get it working was get the appropriate settings in the web.config

<add key="webPages:Version" value="2.0" />
<add key="enableSimpleMembership" value="false" />
<add key="autoFormsAuthentication" value="false" />

and in the _start.cshtml file, add the code

@{
    WebSecurity.InitializeDatabaseConnection("ConnectionStringNameHere", "Users", "ID", "LanID", false);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM