forms authentication - asp.net

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

Related

ASP.NET Identity - where my tables created?

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.

Unable to connect to SQL Server database

When I click the Security tab on the ASP.NET Web Site Administration Tool, I get this error.
"Unable to connect to SQL Server database.".
I'm using Visual Studio 2012
<configuration>
<connectionStrings>
<add name="devices" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\devices.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="users" connectionString="Data Source=(LocalDB)\v11.0;AttachDbfilename=|DataDirectory|\database.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<roleManager enabled="true" />
<compilation debug="true" targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
</system.web>
</configuration>
Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\devices.mdf;Integrated Security=True
Looking at your data source. Does (LocalDB)\v11.0 exist and can you connect to the above DB?
If not that will be the reason....
I have found that every time I create a package for my website (For manual deployments), it overwrites my connection string in the package being created with the above data source.
This can be a blessing some times preventing your new website from launching. (Especially if its in the wrong environment. :)
http://www.connectionstrings.com/ This site is great for helping you creating connection strings for almost any DB.

How can build a basic logon page using ASP.NET 4.0 using Active Directory?

I am trying to build a very basic website using ASP.NET to allow users access the private information by logging into the company Active Directory. Any help is really appreciated.
You will want to set up configuration in the web.config file to tell the ASP.Net app to use forms authentication:
<authentication mode="Forms">
<forms loginUrl="Login.aspx" cookieless="UseCookies" />
</authentication>
Then you will need to create a membership provider that will connect to AD for authentication. Fortunately Microsoft has provided an AD membership provider out of the box, so you can use that. If you set it as the defaultProvider, ASP.Net will automatically use it for authentication.
<membership defaultProvider="AspNetActiveDirectoryMembershipProvider">
<providers>
<add name="AspNetActiveDirectoryMembershipProvider"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ADConnectionString"
connectionUsername="<domainName>\administrator"
connectionPassword="password"/>
</providers>
</membership>
Finally, you will need to set up a connection string to connect to your domain controller:
<connectionStrings>
<add name="ADService" connectionString="LDAP://myCompany.com/DC=myCompany,DC=com"/>
</connectionStrings>
Look here for a good reference with more details.

Godaddy ASP.NET membership database woes

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>

Is it possible to use a different database name with SqlMembershipProvider

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>

Resources