ASP.NET MasterPage

Jay1b

Contributor
Joined
Aug 3, 2003
Messages
640
Location
Kent, Uk.
ASP.NET Logins

I've just watched a few great video's off www.ASP.NET, but they raised a few questions.

The example view of logins (which was what i was originally trying to find out) seemed to store the logins within the ASP server somehow. I want mine stored in an SQL database. Does anyone please have any examples of how to do this?

Thanks
Jay.
 
Last edited:
Just to go into a little more detail.

I can use the login controls no problem, but could someone please tell me where are the usernames and passwords stored for the various users stored?

Is it possible to use to use these with a database? ie: I want a users_t table, which stores all the usernames and passwords and the login control to check this table to decide upon database access. We use a users_t facility with all our other databases and would like to continue doing so.

Thanks

Jay.
 
The default implementation stores them inside a SQLExpress database, if you want to use the default schema but on another DB then the utility aspnet_regsql.exe can be used to configure a given SQL server.

If you do this you will need to alter the web.config to point to the new DB.

If you wish to use a different security mechanism then you would need to create your own RoleProvider and MembershipProvider classes by inheriting from the ones provided in System.Web.Security (or near there anyway).
 
Thanks for you help (once again).

I researched the aspnet_regsql.exe online, and found an interesting article at :
http://msdn2.microsoft.com/en-us/library/x28wfk74(vs.80).aspx

But i cant find anything with regards to changing the web.config file to read this database. I've opened the database i assigned it to, and i can see the generated tables ok, so i know that bit works ok. But i just need to tie it into the project.

Thanks again.
 
Thanks, I'm sure it gives me all the information, but to be honest i think i'm a little out of my depth here. I can find information on writing your own role and membership providers, but as i've decided not to write my own security mechanisms now (its to scary!). I just need to get the project to look at a different database, and thats the only part i cant find mentioned within the link. :(
 
Something like
Code:
<connectionStrings>
   <add 
      name="ExampleConnectionString" 
      connectionString="your connection string here" providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>
<roleManager
    defaultProviderAspNetSqlRoleProvider">
<providers>
      <add connectionStringName="ExampleConnectionString" 
         name="AspNetSqlRoleProvider" 
         type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</providers>
</roleManager>

<membership 
    defaultProvider="AspNetSqlMembershipProvider">
    <providers>
      <add 
        name=" AspNetSqlMembershipProvider"
        type="System.Web.Security.SqlMembershipProvider, System.Web, 
          Version=2.0.3600.0, Culture=neutral, 
          PublicKeyToken=b03f5f7f11d50a3a"
        connectionStringName="ExampleConnectionString"
      />
    </providers>
  </membership>
</system.web>

not tested it (it's a hacked version of one I have used - names removed etc)
 
Thank you very very much :)

I managed to derive this below, which seems to work :)

I dont understand why the user information is being saved into the database though, when the user isnt mentioned? :S

------------------------------------------------------------------
<?xml version="1.0"?>
<!--
Note: As an alternative to hand editing this file you can use the
web admin tool to configure settings for your application. Use
the Website->Asp.Net Configuration option in Visual Studio.
A full list of settings and comments can be found in
machine.config.comments usually located in
\Windows\Microsoft.Net\Framework\v2.x\Config
-->
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">


<appSettings/>
<connectionStrings>
<add
name="ExampleConnectionString"
connectionString="Data Source=RA\SQLExpress;Initial Catalog=CReq;User ID=sa;Password=sisko9"
providerName="System.Data.SqlClient" />
</connectionStrings>

<system.web>

<authentication mode="Forms" />
<roleManager defaultProvider="SqlProvider" enabled="true">
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlRoleProvider"
connectionStringName="ExampleConnectionString"
applicationName="CReq3" />
</providers>
</roleManager>

<membership defaultProvider="SqlProvider">
<providers>
<add
name="SqlProvider"
type="System.Web.Security.SqlMembershipProvider"
connectionStringName="ExampleConnectionString"
applicationName="CReq3" />
</providers>
</membership>



</system.web>

</configuration>
 
Back
Top