Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure db used for ASP.Net Authentication

Tags:

I want to use forms authentication in my asp.net mvc site.

Can I use an already existing sql db (on a remote server) for it? How do I configure the site to use this db for authentication? Which tables do I need/are used for authentication?

like image 818
Thomas Danecker Avatar asked Sep 25 '08 13:09

Thomas Danecker


2 Answers

You can. Check aspnet_regsql.exe program parameters in your Windows\Microsoft.NET\Framework\v2.xxx folder, specially sqlexportonly.

After creating the needed tables, you can configure: create a connection string in the web.config file and then set up the MemberShipProvider to use this connection string:

  <connectionStrings>
    <add name="MyLocalSQLServer" connectionString="Initial Catalog=aspnetdb;data source=servername;uid=whatever;pwd=whatever;"/>
  </connectionStrings>

<authentication mode="Forms">
  <forms name="SqlAuthCookie" timeout="10" loginUrl="Login.aspx"/>
</authentication>
<authorization>
  <deny users="?"/>
  <allow users="*"/>
</authorization>
<membership defaultProvider="MySqlMembershipProvider">
  <providers>
    <clear/>
    <add name="MySqlMembershipProvider" connectionStringName="MyLocalSQLServer" applicationName="MyAppName" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
  </providers>
</membership>

Ps: There are some very good articles about the whole concept here.

like image 92
Biri Avatar answered Sep 30 '22 19:09

Biri


The easiest manner is to just use the windows interface for the aspnet_regsql.exe application.

You can find it in the c:\windows\microsoft.net\framework\v2.0.50727 folder.

Just type in aspnet_regsql.exe, it will then open a wizard, this way you don't need to remember any command line switches.

like image 42
Mitchel Sellers Avatar answered Sep 30 '22 19:09

Mitchel Sellers