0

Simple question. I know that in the default MVC application in Visual Studio, you can register a user. So I want to be able to put that info in a database and use ADO.net or LINQ to SQL to be able to communicate. How do I do this?

1
  • The same like every other application on every other framework? Commented Dec 27, 2009 at 20:05

3 Answers 3

4

Do you have a database or do you want to create a new one? If you have one just create a connection in server exploer, add new Model in Visual studio, select LinqToSql Classes, select tables from your connection and drag and drop the tables you need to the design surface. Then you can access your model from your controller where the user data is posted to. Check this thread for example of saving.

If you don't have a database you obviously have to design and create it first

Sign up to request clarification or add additional context in comments.

Comments

2

Some might argue, but you probably do not want to use the built-in membership provider. The reason is that it generates its own default schema which is good to start with, but it's better to just bite the bullet and design your own. That way, you're in control of your application, and do not have to migrate your database whenever some change is required.

Comments

1

The sample stuff in ASP.NET MVC uses the built-in membership and forms authentication in ASP.NET. In the Web.config, you can configure it to store the data in SQL Server rather than the default which I think might is SQLExpress. MSDN has an article on how to do this:

How To: Use Forms Authentication with SQL Server in ASP.NET 2.0

You basically just run a sql script and it generates a bunch of tables and stored procedures in whatever database you are already using. You can then access the database directly or through the membership API.

Alternatively, you can roll your own implentation of IMembershipService which just has a few methods to handle:

public interface IMembershipService
{
    int MinPasswordLength { get; }

    bool ValidateUser(string userName, string password);
    MembershipCreateStatus CreateUser(string userName, ...);
    bool ChangePassword(string userName, ...);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.