I have created sample register page to create user using ASP.NET Identity. Actually, I am working with this project since long back; which means, database is already existing.
From Register.aspx page, when clicked on the Register button, getting the message like "User created successfully"; but could not able to find out where relevant tables created.
Below is the connectionstrings section of my web.config file. Please note that, second connectionString "LocalDBConnectionString" is existing but NOT using anywhere, and in-fact not working.
I have verified with all the relevant databases for membership tables, but could not find relevant one.
<connectionStrings>
<add name="ASHOKConnectionString" connectionString="Data Source=SHRESTASOFT\SQLEXPRESS;Initial Catalog=ASHOK;Persist Security Info=True;User ID=sa; Password=tentod" />
<add name="LocalDBConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\ClassDB.mdf;Integrated Security=True" />
<add name="ASHOKEntities" connectionString="metadata=res://*/EntityFramework.ASHOK.csdl|res://*/EntityFramework.ASHOK.ssdl|res://*/EntityFramework.ASHOK.msl;provider=System.Data.SqlClient;provider connection string="data source=SHRESTASOFT\SQLEXPRESS;initial catalog=ASHOK;persist security info=True;user id=sa;password=tentod;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
<add name="NORTHWINDDataContext" connectionString="metadata=res://*/EntityFramework.NorthwindDataContext.csdl|res://*/EntityFramework.NorthwindDataContext.ssdl|res://*/EntityFramework.NorthwindDataContext.msl;provider=System.Data.SqlClient;provider connection string="data source=SHRESTASOFT\SQLEXPRESS;initial catalog=NORTHWND;persist security info=True;user id=sa;password=tentod;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
Where could the database be created?
Update - One more help required: Please observe that ASHOKConnectionString is existing inside connectionstrings section of web.config. This is the one I am using currently for other pages. If I want to get my ASP.NET Identity related tables into this database, how can I do? Can anybody please suggest me!
You can find where the members are stored by looking the membership field on web.config. For example you have to see something like:
<roleManager ... >
<providers>
<clear/>
<add connectionStringName="ASHOKConnectionString" ... />
</providers>
</roleManager>
<membership >
<providers>
<clear/>
<add connectionStringName="ASHOKConnectionString" ... />
</providers>
</membership>
and inside that database that is used for members, there are 11 tables that starts with aspnet_ and there are your member.
Related
im trying to get role provider working in multiple environments and hitting a wall
(link text)
i should be able to dynamically set the connectionString property of the web.congig item on app_onstart to the correct DB conection String to get it to work...
can anyone show me how to dynamically alter items in the web.config?
im guessing reflection...
<roleManager enabled="true" defaultProvider="SqlRoleManager">
<providers>
<clear/>
<add name="SqlRoleManager" type="System.Web.Security.SqlRoleProvider" connectionStringName="ISConnectionString_prod" applicationName="IS"/>
</providers>
</roleManager>
i want to adjust the connectionStringName value in the above snipet
thanks
If you're using VS2010, you can get it to automatically apply transforms to your config files depending on which environment you're publishing to.
We use this to set connection strings, payment provider config settings (sandbox mode, username, etc.) and a couple of other things like how exceptions are handled.
If you're not publishing, you can actually hook these transforms straight into the build engine by editing the project file.
This makes it incredibly simple to maintain (You have a web.config and a web.Live.config which contains the transforms). It also makes the whole process far less error-prone
eg:
web.config
<connectionStrings>
<clear />
<add name="OurConnectionString" connectionString="Data Source=DevDbHostname;Initial Catalog=DevDb;user id=Username;password=Password;MultipleActiveResultSets=True" />
</connectionStrings>
web.Release.config
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="OurConnectionString"
connectionString="Data Source=LiveDbHostname;Initial Catalog=LiveDb;user id=Username;password=Password;MultipleActiveResultSets=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
</configuration>
As long as the permissions allow it (you will have to change them), you can treat the web.config just as any other XML file. Knowing that, you can simply use an XDocument and pop in a new XElement where you want it. But be very careful and be sure to save some backups!
Ok so I am using forms authentication in my web site and I defined this in my config. Therefore I have an ASPNETDB.MDF. So do I need to have a database called ASPNETDB.MDF in my web host? If that is the case then how do I connect this so that my site uses this to verify users? I am sorry this seems to be like a very noob question
Place the ASPNETDB.MDF in your App_Data folder.
The connection string to use is <add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf" />
When you hook this connection string to your membership provide the authentication will use your ASPNETDB.MDF file.
-------------------Try the following-----------------
Sorry place a above the connection string above you should be able to change the name of the connection string. You will also need to change this in your membership element.
<connectionStrings>
<clear />
<add name="NewConnectionString" connectionString="Data Source=.\SQLExpress;Integrated Security=True;User Instance=True;AttachDBFilename=|DataDirectory|aspnetdb.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<membership>
<providers>
<clear/>
<add name="AspNetSqlMembershipProvider"
connectionStringName="NewConnectionString"
...
type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</membership>
You dont have to use a database to use forms authentication, you can define the entries in the web.config file if you like. It depends on the MembershipProvider that you are using.
Have a look here for an example
I purchased a Windows shared hosting account on godaddy that came with 2 MSSQL databases. I setup one to hold my site data and the other installed aspnet membership schema to store site members. The site works perfectly even displaying data from the 1st database. However when I try to login or register I get this nasty error
Exception Details:
System.Configuration.Provider.ProviderException:
The SSE Provider did not find the
database file specified in the
connection string. At the configured
trust level (below High trust level),
the SSE provider can not automatically
create the database file.
Ive gone through my web.config and there's nothing wrong with my 2 connection strings. It seems godaddy has a problem with using 2 mssql databases simultaneously when 1 is for membership.
Does anyone know a solution or a workaround?
I hope my experience benefits every one. Basically if you want to avoid aspnet membership problems on godaddy always use "LocalSqlServer" as the connectionstring. i.e
<providers>
<remove name="AspNetSqlMembershipProvider" />
<add name="AspNetSqlMembershipProvider" connectionStringName="LocalSqlServer"
..other attributes here... />
</providers>
Then create the "LocalSqlServer" connectionString...remember to remove it first
<connectionStrings>
<remove name="LocalSqlServer"/>
<add name="LocalSqlServer"
connectionString="Data Source=xxxx; Initial Catalog=xxx; User ID=xxx; Password=xxx;"
providerName="System.Data.SqlClient" />
</connectionStrings>
I ran into same problem and am using MVC3. Above solution works but with some other changes in MVC3. It took me long time to figure it out so if anybody has similar issue in MVC3 it might help them:
Search for "connectionStringName" in web.config and replace the name with connectionStringName="LocalSqlServer"
Also under connectionstrings make sure
-To add (As this is important for all who are using shared hosting it will replace machine.config LocalSqlServer connectionstring with yours.)
-Keep your current connectionstring (In my case it is FilmiDb, this is required for you to connect to the database in EF model. Without this you will get errors.)
<connectionStrings>
<remove name ="LocalSqlServer"/>
<add name="LocalSqlServer" connectionString="Data Source=.\SQLExpress;Initial Catalog=SofilmiDb;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
<add name="FilmiDb" connectionString="Data Source=.\SQLExpress;Initial Catalog=FilmiDb;Integrated Security=SSPI" providerName="System.Data.SqlClient" />
</connectionStrings>
Can I specify a different database than ASPNETDB using SqlMembershipProvider? I am developing a site on a shared host, and have to restrict my data schema to a single provided database.
I was roundly scolded last time I suggested rolling my own authentication code.
Alternatively, is there some other packaged authentication system I could drop in and configure to use an arbitrary database and tables from asp.net?
You can install the ASP.Net Membership Schema to any SQL database by using the aspnet_regsql command line tool.
You can also specify any connection string you'd like for your membership provider. Simply add something like this to your membership declaration in your web.config file:
<connectionStrings>
<add name="MyConnectionString" connectionString="Database=MyDatabase;Server=xxx;User=xxx;Pwd=xxx;" providerName="System.Data.SqlClient"/>
</connectionStrings>
<membership defaultProvider="MyProvider">
<providers>
<add connectionStringName="MyConnectionString" applicationName="/Test"
description="MyProvider" name="MyProvider" type="SqlMembershipProvider" />
</providers>
</membership>
The previous answer is largely correct, but I had a problem until I fully qualified the "Type" value to be "System.Web.Security.SqlMembershipProvider".
<membership defaultProvider="MyProvider">
<providers>
<add connectionStringName="MyProvider"
applicationName="/Test"
description="MyProvider"
name="MyProvider"
type="System.Web.Security.SqlMembershipProvider" />
</providers>
</membership>
Very simple question actually:
I currently have IIS anonymous access disabled, users are automatically logged on using their Windows login. However calling User.IsInRole("Role name") returns false. I double-checked User.Identity.Name() and the "Role name" and it should return true.
I currently have this in my Web.Config:
UPDATE
I was calling User.IsInRole("Role name") where I should call User.IsInRole("DOMAIN\Role name")
However I still like to know if the <membership> entry is needed at all?
What should I change? (and is the <membership> entry needed at all?)
<authentication mode="Windows">
<forms
name=".ADAuthCookie"
timeout="10" />
</authentication>
<membership defaultProvider="ADMembershipProvider">
<providers>
<clear/>
<add
name="ADMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="XXX\specialAdUser"
connectionPassword="xx"
/>
</providers>
</membership>
<roleManager enabled="true" defaultProvider="WindowsProvider">
<providers>
<clear />
<add name="WindowsProvider" type="System.Web.Security.WindowsTokenRoleProvider" />
</providers>
</roleManager>
If you use Windows authentication IsInRole will work with no extra configuration, as long as you remember to prefix the role with the domain, i.e. DOMAIN\groupName.
In addition you can role (pun intended) your own and use Windows auth against, for example, a SQL Role Provider, where you don't want your AD littered with custom roles for your application.
So no, you don't need the provider configuration at all.
The membership provider here isn't going to help. The ActiveDirectoryMembershipProvider seems to best(only?) fit with Forms authentication.
BlogEngine.NET has an Active Directory role provider.
Pretty sure the only thing you need in there is the roleManager group (along with the base authentication mode='windows' setting)
Out of the box, there's no role provider to use Active Directory directly. You can use the role table in the ASP.NET membership- and role-system, or you can use Authorization Manager (AzMan).
There's an article on CodeProject which shows the implementation of a role provider which works against the Active Directory - with full source code. Maybe this helps?
Marc