Jay1b Posted March 1, 2006 Posted March 1, 2006 (edited) ASP.NET Logins I've just watched a few great video's off http://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. Edited March 1, 2006 by Jay1b Quote
Jay1b Posted March 2, 2006 Author Posted March 2, 2006 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. Quote
Administrators PlausiblyDamp Posted March 3, 2006 Administrators Posted March 3, 2006 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). Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted March 3, 2006 Author Posted March 3, 2006 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. Quote
Administrators PlausiblyDamp Posted March 3, 2006 Administrators Posted March 3, 2006 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/ASPNETProvMod_Intro.asp is worth a read through as it covers the relevant sections of web.config and the appropriate values. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted March 3, 2006 Author Posted March 3, 2006 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. :( Quote
Administrators PlausiblyDamp Posted March 3, 2006 Administrators Posted March 3, 2006 Something like name="ExampleConnectionString" connectionString="your connection string here" providerName="System.Data.SqlClient" /> defaultProviderAspNetSqlRoleProvider"> name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> defaultProvider="AspNetSqlMembershipProvider"> name=" AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="ExampleConnectionString" /> not tested it (it's a hacked version of one I have used - names removed etc) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jay1b Posted March 3, 2006 Author Posted March 3, 2006 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> Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.