Link to home
Start Free TrialLog in
Avatar of awilderbeast
awilderbeastFlag for United Kingdom of Great Britain and Northern Ireland

asked on

asp.net login.aspx DefaultMembershipProvider to query an sql table for users?

HI all,

i jsut created a new web app in visual studio and it auto creates these login forms for you. i wondered how they worked so submitted the form to get the error.

i was wondering how to configure these default builtin forms to connect to an sql users table, or do i change the submit button to query the db, and it cant be done via web config?

Thanks

Line 21:     <membership defaultProvider="DefaultMembershipProvider">
Line 22:       <providers>
Line 23:         <add name="DefaultMembershipProvider" type="System.Web.Providers.DefaultMembershipProvider, System.Web.Providers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" connectionStringName="DefaultConnection" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/" />
Line 24:       </providers>
Line 25:     </membership>

Open in new window

Avatar of EMB01
EMB01
Flag of United States of America image

The default membership provider in asp.net mvc uses it's own database.  Are you wanting to use a custom database?
SOLUTION
Avatar of Alan Warren
Alan Warren
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is the easiest way I found to make the membership provider use your own database (a question I asked on stackoverflow):

http://stackoverflow.com/questions/12159926/vb-asp-net-mvc-custom-membership-provider
Avatar of awilderbeast

ASKER

in my db i have a load of tables named aspnet_ when i use the login page its looking for tables without the name aspnet_ do i rename them?

also can i alter these tables without breaking the logon? i.e the userID column wants a guid!
i cant be faffed to create guids, i want to set it to an integer and have it auto incremenent

can i make those changes without breaking it?

Thanks
If you want to use your own tables, you must follow the steps I sent you in the link http://stackoverflow.com/questions/12159926/vb-asp-net-mvc-custom-membership-provider.  You have to implement your own membership provider.  It's not that hard and you can use all the same methods; you just have to write them yourself (via overrides).  I only am using the one right now, AuthenticateLogin().
You can do anything you want to, but the Membership Class won't function as expected if you do; unless you over-ride it, but why would you? It's one of the finest objects uncle Bill has given us for a long time...

Alan
ah i use that class to create my users then?

do i just run the below from anywhere and it will create?
also do i rename all the aspnet_ tables to tables without the aspnet_ as all my pages are looking for tables without it?

public static MembershipUser CreateUser(
	string username,
	string password,
	string email,
	string passwordQuestion,
	string passwordAnswer,
	bool isApproved,
	Object providerUserKey,
	out MembershipCreateStatus status
)

Open in new window

Yes, you could create your users with the new class that inherits the MembershipProvider.

You could run it anywhere you have instantiated the Membership provider class.  Just access methods like:

Membership.ValidateUser("userName")

This is completely separate of your current tables.  This is so you can use your own database.
Just having issues adding a user at the mo. i thought if i used the in built register.aspx form it would create me a user.

no good, it keeps having different field names, which i can easily changed but just got hit with one i couldnt do anything about...

Cannot insert the value NULL into column 'LoweredApplicationName', table 'TESTDB.dbo.Applications'; column does not allow nulls. INSERT fails.
The statement has been terminated.

seems the register.aspx file doesnt auto fil in that field, should i change it so it could be null? i dont want to break it...
I don't suggest using your old database, if that's what you're doing.  It may have fields that require certain values.  If you're using a new membership provider, just start fresh by using a new table.  If you have old data you want to use, just write a migration.
im using the DBs created from the aspnet_reg.exe wizard

and for the accounts forms, using the default built in ones visual studio creates when you do a new app
If you're just going to use the default databases then why do you need a custom membership provider?  What are you trying to do?
i was just trying to use all the default login stuff, but they arent working...

the DB connections work but the default pages keep throwing out errors, as above
Follow this tutorial to use the default membership provider properly http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-7 otherwise, read this link to roll your own membership provider http://stackoverflow.com/questions/12159926/vb-asp-net-mvc-custom-membership-provider.
ok i clicked asp.net config in visual studio
the url looks like this
http://localhost:62398/asp.netwebadminfiles/default.aspx?applicationPhysicalPath=\\ITVM\c$\TEST\&applicationUrl=/TEST

then i get this after its shown me the first page:-
There is a problem with your selected data store. This can be caused by an invalid server name or credentials, or by insufficient permission. It can also be caused by the role manager feature not being enabled. Click the button below to be redirected to a page where you can choose a new data store.

The following message may help in diagnosing the problem: Unable to connect to SQL Server database.


when i press the button to choose the datasource it says aspNetSqlProvider and thats the only option where is that set/ how do i create one?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Can you access the db catalog via Sql Server Management Studio (SSMS)?
You possibly need to login to SSMS using some admin credentials like 'sa', ensure the database has an associated Login defined like some_user and that some_user is mapped to your catalog.

Essentially you need to be able to log into SSMS using the credentials as defined in your connection string, in your web.config. If you can't, then you either need to modify your connectinstring or set up credentialling (Login, Role, Mapping etc...) in the sql server instance for the user defined in your web.config.

As a temporary measure, you could modify your connection string to use the 'sa' credentials, I strongly suggest you don't leave it that way, but if any user can establish a connection, 'sa' can.

Alan
few!

I finally did it!
I just had to change the providers to SQL providers, all is working great!, good stuff this .net eh!

thanks for your help!
This and adding SQL providers in web config gets it going
@jarmod101:  Thanks, it wasn't a big deal I just wanted them to know for future reference "if someone is trying to help you find your solution and takes the time to post several comments to you to that effect" you should take a moment to appreciate that in whatever small way you can.