In the project's Web.Config of MVC, there are tags such as
<profile defaultProvider="DefaultProfileProvider">
<providers>
<add name="DefaultProfileProvider"
type="System.Web.Providers.DefaultProfileProvider, System.Web.Providers, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
connectionStringName="OfficeData" applicationName="/" />
</providers>
</profile>
<membership defaultProvider="DefaultMembershipProvider">
...
</membership>
<roleManager defaultProvider="DefaultRoleProvider">
...
</roleManager>
What are they? And what is their purpose?
Those elements are the basic configuration for ASP.Net Membership, the default authentication/authorization system for ASP.Net. There's lots of configuration you'll want to do, but at a high level you have three sets of configuration:
profile - a system for saving user related profile information (By default a weird data schema is used, and should be avoided)
membership - the central place for configuring authentication (passwords storage, resetting, etc.)
roles - your users will be grouped into roles within you app, this is where you configure that
ASP.Net Membership is solid, but dated and inflexible. The new standard is ASP.Net Identity
Related
So I have to work on this project (ASP.NET MVC 4 with Umbraco) that uses Entity Framework and I think UmbracoMembeShipProvider.
Now I have to add Roles to the project. In the DB there's a Users table and some few others. There is no Identity/Roles or the sort in the DB. I tried to create a Roles table and a junction table between Users and Roles but then I couldn't update the models. I made an .edmx schema file and it didn't pick up the junction table, just the Roles table with all the columns pilled up from the junction table.
I tried to approach it by making a Roles entity in the .edmx file and then update the DB via migrations, that also didn't work because the project is stuctued in a way that is has a 'Core' project where all the models are and then a 'Web' project where some other models are. And it gave all heaps of errors.
In the Web project there's a 'Migrations' directory with 2 classes one of which has 2 empty methods (up/down) and one that creates some indexes and then a bunch of commented code.
I'm also quite a newbie in ORMs in general so I don't know how to approach this problem, continuing where the other devs, before me, left off.
In the meantime I'll pick up some tutorials about EF but any help or guidance will be really appreciated.
You need to include the necessary settings in your web.config file which references a connection string pointing to a database where the user/role tables exist. It should look something like this.
<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider"
type="umbraco.providers.members.UmbracoMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
defaultMemberTypeAlias="Another Type"
passwordFormat="Hashed" />
<add name="UsersMembershipProvider"
type="umbraco.providers.UsersMembershipProvider"
enablePasswordRetrieval="false"
enablePasswordReset="false"
requiresQuestionAndAnswer="false"
passwordFormat="Hashed" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
<providers>
<clear />
<add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider" />
</providers>
</roleManager>
<roleManager enabled="true" defaultProvider="UmbracoRoleProvider">
<providers>
<clear />
<add name="UmbracoRoleProvider" type="umbraco.providers.members.UmbracoRoleProvider" />
</providers>
</roleManager>
<appSettings>
<add key="umbracoDbDSN" value="server=localhost;database=MSSM;user id=db_user;password=password" />
When I add
<roleManager enabled="true"></roleManager>
to my web.config, I get an error
Unable to connect to SQL Server database
occurs on this line of code:
System.Web.Security.Roles.AddUserToRole(m.UserName, "admin");
I added this to the web.config and it solved my problem:
<system.web>
<roleManager enabled="true" defaultProvider="CustomizedRoleProvider">
<providers>
<add name="CustomizedRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="DefaultConnection" />
</providers>
</roleManager>
</system.web>
I had the exact same error when I had enabled believing I was enabling ASP.NET Identity 2. They are not the same! The enabled an old version of identity management which uses a different table structure to ASP.NET Identity 2 (which doesn't need "enabling" by the way - it's just there).
check the connection String.
If you are intentionally using the old role-manager and still getting the error you might be looking at the default localdb instead of your database, in which case you can modify to point at any connection string you want:
<roleManager
enabled="true"
cacheRolesInCookie="true"
defaultProvider="OurSqlRoleProvider"
>
<providers>
<add
connectionStringName="DefaultConnection"
applicationName="/"
name="OurSqlRoleProvider"
type="System.Web.Security.SqlRoleProvider" />
</providers>
</roleManager>
If you are are after using ASP.NET Identity 2, here's an article on it:
http://johnatten.com/2014/04/20/asp-net-mvc-and-identity-2-0-understanding-the-basics/
how can i use in Umbraco 7 the internal Users and roles who use the BackOffice and my custom users and roles (which comes from an external SQL database.
i want log in umbraco backoffice with the umbraco users as it is and with seperate Login want use external users. i have already changed the web.config
<add name="mynewMembershipProvider" type="mynewMembershipProvider, mynew"
<add name="mynewrovider" type="mynewrsRoleProvider"/>
when i go now to my custom Login i can Login my custom user . but when i try
User.Identity.IsAuthenticated
or
User.IsInRole("xyz")
umbraco is always looking at the umbraco roles.
what did i have done wrong
best regards Michael
If I understand you correctly, you are leaving CMS and back office Users as-is, and you want to allow Member login on the public facing side of your site with a custom provider?
Did you set the default provider to your new membership provider?
<membership defaultProvider="mynewMembershipProvider">
...
</membership>
The default provider in the membership section should always point to the provider being used for public-facing Members - the backoffice interally asks for the UsersMembershipProvider every time it needs to authenticate, so changing the default will not affect it at all.
It is also possible depending on your set up (I haven't tried this) that if you did not include a <clear/> directive then the original Umbraco member provider is causing problems.
Here is a full working <membership> section using a custom BCrypt hashing provider from an Umbraco 7 install of mine:
<membership defaultProvider="BCryptMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add
name="BCryptMembershipProvider"
type="cFront.Web.Security.BCryptMembershipProvider"
connectionStringName="umbracoDbDSN"
requiresUniqueEmail="0"
/>
<add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" passwordFormat="Hashed" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="BCryptRoleProvider">
<providers>
<clear />
<add name="BCryptRoleProvider" type="cFront.Web.Security.BCryptRoleProvider"
connectionStringName="umbracoDbDSN"
availableRoles="SuperUser,Administrator,Manager,User"
/>
</providers>
</roleManager>
How to prevent that error?
The password supplied is invalid. Passwords must conform to the
password strength requirements configured for the default provider.
I do migration users from the old ASP website to a new ASP .NET MVC 4 Website.
var newUser = System.Web.Security.Membership.CreateUser(oldUser.Login, oldUser.Password, userEMail);
web.config
<membership defaultProvider="DefaultMembershipProvider">
<providers>
<add connectionStringName="MembershipConnection" enablePasswordRetrieval="false"
enablePasswordReset="true"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5"
minRequiredPasswordLength="3"
passwordStrengthRegularExpression=""
minRequiredNonalphanumericCharacters="0"
passwordAttemptWindow="10"
applicationName="MyCoolApplication"
name="DefaultMembershipProvider"
type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
</providers>
</membership>
And it seems I need correct solution for some users who have incorrect password.
How I can manage it in a proper way?
Thanks!
Based on the assumption that you are using the same .NET MVC version. Why not skip C#, use the SQL knowledge we got from school?
Insert into [newDB].[table] (columns)
select [oldDB].[table].[columns]
from [newDB].[table]
If you upgraded MVC version, the password hash might not be compatible.
Lastly, you should be able to work around it by altering the password requirements in web.config
I am using the following provider to look up users from ADAM. I would be able to like to change the connection string dynamically depending on the type of user. How can I achiev this?
<add name="con1" connectionString="LDAP://con1.url" />
<add name="con2" connectionString="LDAP://con2.url" />
<providers>
<add name="ConnectionProvider" connectionStringName="con1" type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" attributeMapUsername="userPrincipalName" enableSearchMethods="true" />
</providers>
You can get specific sections of the .config by using the ConfigurationManager.GetSection() method (System.Configuration namespace). From here, just apply the logic and select the connection string you want.