views:

52

answers:

2

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

A: 

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

James Westgate
+1  A: 

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>
MIchael Grassman
correct me if I am wrong, but we don't have this connection string when testing it at local host?
EquinoX
Are you referring to the source=.\SQLExpress. If so the local aspnetdb.mdf is a SQLExpress database and the .\ is just saying to use the machine that the code is placed on. The attachedDBFilename attribute takes priority over the source. If you were referring to something else please let me know.
MIchael Grassman
maybe this can clear up my confusion, if I follow the suggestions above then I can't change the name name="LocalSqlServer" right? it must be LocalSqlServer as the engine will look for that name to reference to the forms
EquinoX