I've a WCF web the config file which requires multiple membership provider due to reason below:
1. One membership for WCF which uses application A.
e.g.
<add name="MySqlMembershipProvider1"
connectionStringName="ApplicationServices"
applicationName="ApplicationA"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
type="System.Web.Security.SqlMembershipProvider" />
The other membership for creating and updating asp.net users.
<add name="MySqlMembershipProvider2"
connectionStringName="ApplicationServices"
applicationName="ApplicationB"
requiresQuestionAndAnswer="false"
requiresUniqueEmail="true"
type="System.Web.Security.SqlMembershipProvider"
/>
How do I specify the provider name on above scenario.
SqlMembershipProvider p1 = SqlMembershipProvider)
Membership.Providers["MySqlMembershipProvider1"];
....//
then using the membership providers's instance p1 for Application you can do whatever you need
SqlMembershipProvider p2 = (SqlMembershipProvider)
Membership.Providers["MySqlMembershipProvider2"];
....//
please see this link
Related
I'm developing an ASP.NET MVC3 website and I'm using the Microsoft ASP.NET Universal Providers.
Web.config :
<connectionStrings>
<add name="MyContext" connectionString="data source=tcp:***.database.windows.net,1433;Initial Catalog=***;User Id=***;Password=***;Trusted_Connection=False;Encrypt=True;Connection Timeout=30" providerName="System.Data.SqlClient" />
</connectionStrings>
...
<roleManager defaultProvider="DefaultRoleProvider" enabled="true">
<providers>
<clear />
<add name="DefaultRoleProvider" type="System.Web.Providers.DefaultRoleProvider" connectionStringName="MyContext" applicationName="/" />
</providers>
</roleManager>
The connectionStrings is ok in Azure.
Aspnet tables and storedprocedures I added by using the query script. Data in tables added by migrations. I checked it in management portal.
I can get profile membership and profile data, but the the code below returns empty list.
var userName = User.Identity.Name;
var userRoles = Roles.GetRolesForUser(userName).ToList();
userName is correct and table aspnet_UsersInRoles contains correct data too.
There is no exceptions on page.
Why the userRoles is empty?
I fix this problem by creating the custom provider, which is inherited from SqlRoleProvider.
I want to add user registration to my site and I will need to create admin, who manages users. I am using authentication of ASP.NET. I can create user with Account/Register, listing them with Membership.GetAllUsers() on my admin panel and delete with Membership.DeleteUser( username )
I need help about admin. How can I create 1 admin and make sure nobody can be admin, be only simple user?
And what is role of user in Membership.CreateUser( model.UserName, model.Password, model.Email, null, null, true, null, out createStatus ) method of Account/Register?
For MVC account management I have found the MembershipStarterKit to be very useful. It sounds like you want Role based authentication which it supports very well.
The Membership.CreateUser function that you are referring to is not related to admin or role based security and is used only to create the user itself.
You can use the IIS .NET Users tool but because that targets .NET 2.0 you need to do some config around that to make it work. You need to create a new IIS application that uses the same connection strings as the real application.
That application needs a webconfig that looks like
<configuration>
<connectionStrings>
<add name="MyConnectionString" connectionString="same as my production application membership connection string" providerName="same as my production application provider" />
</connectionStrings>
<system.web>
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
<membership>
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, EnablePasswordReset=true" connectionStringName="MyConnectionString" applicationName="/" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="AspNetSqlRoleProvider">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="MyConnectionString" applicationName="/" />
</providers>
</roleManager>
</system.web>
</configuration>
When you add the application with this webconfig structure you need to make sure that you use an app pool that uses .NET v 2.0 integrated pipeline (DefaultAppPool should work).
One this is done, within this mini application you will have access to the .Net users feature where you can add and edit users and roles. However, this is not as useful a tool as the MembershipStarterKit.
I have an MVC 3 web application using Entity Framework to access the projects database. However, the project also uses a second database for Memberships called ApplicationServices. The MvcMembership package uses this database for authentication purposes. Now, I added a custom stored procedure in the ApplicationServices database that I would like to call from my application. How can I do that?
I guess I could do so by using the Membership Provider, but I am not sure how to do so.
Here is how it is defined in my Web.config file:
<add name="ApplicationServices" connectionString="Data Source=.\SQLEXPRESS;Persist Security Info=false; Initial Catalog=ApplicationServices; User ID=******; Password=******" />
...
<membership defaultProvider="AspNetSqlMembershipProvider">
<providers>
<clear />
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" ... applicationName="/" />
</providers>
</membership>
No you can't call it from the default SqlMembershipProvider because this is a custom Stored Procedure and the Membership Provider know nothing about it.
Anyway you still could access this stored procedure like normal. Or you may make custom MembershipProvider and use this StoredProcedure in it. It depends on what and why you use this StoredProcedure
I'm new to ASP.NET and have just starting to learn ASP.NET MVC 3. I've started a new ASP.NET MVC 3 project using the default template, which already has most of the membership stuff already configured. Now I'm trying to understand what is really going on behind the scenes.
I've found that default template defines an IMembershipService interface which is implemented by the AccountMembershipService class which basically just wraps a System.Web.Security.MembershipProvider. From the comments in the code is sounds like this abstraction is done to facilitate unit testing.
The default MembershipProvider is set in the Web.config file. My project, which was created from the default template, it is set to the SqlMembershipProvider.
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices"
enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false"
maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10"
applicationName="/" />
</providers>
</membership>
This references a connection string in the Web.config file, which references a SQL Express database "aspnetdb.mdf".
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
When I first created my project there was no aspnet.mdf file. But after running my app and registering a new user this file was automatically generated tables and all. What's going on here? What creates this file and specified the tables that should be created?
These are created by the SqlMembershipProvider class. If you'd like, you can customize your config file to use a different membership provider or to tell it what existing database to use.
Use this tool to add the appropriate tables, etc to your existing SQL Server installation: http://msdn.microsoft.com/en-us/library/ms229862(v=VS.100).aspx
I am trying to set minimum password requirements for my membership provider in Umbraco. Currently my web.config membership section looks like this:
<membership defaultProvider="UmbracoMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="UmbracoMembershipProvider" type="umbraco.providers.members.UmbracoMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" defaultMemberTypeAlias="Another Type" passwordFormat="Hashed" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" />
<add name="UsersMembershipProvider" type="umbraco.providers.UsersMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" passwordFormat="Hashed" minRequiredPasswordLength="7" minRequiredNonalphanumericCharacters="1" />
</providers>
</membership>
However, when I login in through the website and change my password, it will let me use a password of any length and makeup. Is there something I'm missing?
Thanks!
Typically custom membership provider settings are passed as custom xml attributes on the tag itself. You can see one there already: "userIsOnlineTimeWindow." Fire up Reflector and have a dig around the Assembly containing that provider, or praise-jeebus, RTFM. :D
-Oisin