views:

189

answers:

2

Hello guys,

I'm trying to use ASP.NET MVC to my new project and have been expected that the user authentication should be rather simple there. My goal is to have a separate user database table in my main database.

I thought that the SqlTableProfileProvider should be the solution. So I added the corresponding table into my database and changed the web.config file. But it seems no matter what I change there, my web application still using the default authentication (via ASPNETDB.mdf file).

What could be the problem?

(my web.config file beginning is:)

+1  A: 

See this reference on how to create the standard application services tables and associated database entities in your SQL server database. Once done it should be a simple matter of changing the default Application Services connection string in the web.config file to use the built-in providers for membership, roles, and profiles.

tvanfosson
Well, RTFM is nice advice... ;) but it would be great to get a step-by-step guide on how to use my own table (some extra attributes such as date of birth, etc.) for ASP.NET MVC user authentication. I expected that it's rather simple in ASP.NET MVC but it seems not. Have you ever seen such a sample?
Serge
There's another manual on how to create your own membership provider, http://msdn.microsoft.com/en-us/library/f1kyba5e.aspx, but really I think you could do pretty much everything with the built-in membership and profile providers -- date of birth is really a profile item. If you don't implement a membership provider -- default or custom - you'll need to change the account login/logout/changepassword actions. Really the simplest thing to do is use the built-in tables and the hooks for the providers. The next simplest thing to do is use that pattern as a guide for your own implementation.
tvanfosson
It seems that SqlTableProfileProvider should help, but I can't find any example of using it with ASP.NET MVC.
Serge
It's just another profile provider, correct? Use the membership provider for authentication and plug that provider in place of the default provider for profiles. You don't need to register the standard profile stuff in the database, you can limit it to just the membership and role tables/procs.
tvanfosson
...the samples should work the same way as at http://www.asp.net/downloads/sandbox/table-profile-provider-samples/, since this is just web.config stuff. The only tricky bit might be the ProfileCommon class since MVC won't create that for you. See here: http://stackoverflow.com/questions/79129/implementing-profile-provider-in-asp-net-mvc/434793#434793
tvanfosson
+1  A: 

Do what I do and forget about rolling your own membership provider etc or using sqltableprofileprovider - instead extend the tables that the default membership adds through relations to your own table(s) which contains the extra data you want to store.

So, add another table to your database called 'Details', for example, then set the primary key to be related 1 to 1 to the primary key of the aspnet_Users table. Use this new table as you would any other. When you want the primary key of a user, use the membership api to grab it.

not tested!

Guid userID = (Guid)Membership.GetUser(username).ProviderUserKey;

Then add the data you require to your details table and your set.

Just seems more flexible to me - although I'm probably doing it all wrong! :)

Sergio
sorry that should really have been a comment to the answer above as its more to do with that discussion than a direct answer to your question.
Sergio