I am trying to create my first web application using ASP.NET. I’ve created new sample ASP.NET project application.
First of all I want to understand how do I switch from local App_Data file to proper database and how whole authentication process is working.
-
Db switch. What I did is, attached current example of .mdf file through SQL management studio on a server. But I am not sure how should I modify my connection string. Could you help me please?
connectionString=”data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true”
-
Could you please explain how authentication is working? Say after user enter its credentials and hits enter, somewhere in a code it has to validate username and password, but I can’t find where it happens.
Lets say my user A is Moderator and user B is simple user. How should I detect which one it is? How do I display extra features for user A, since he is a Moderato?
For the connection string, the best option is to use Visual Studio. Go to Data -> Add New Data Source and follow the UI. Failing that, connectionstrings.com is a great reference.
There are different types of authentication in ASP.net, but given that you want to implement roles (user/moderator), Forms Authentication is probably a good choice. There are lots of resources on how to set this up, see here for example.
The final step is to implement roles so that your application knows who is a user, and who’s a moderator. Once you have this configured correctly, your application can use simple logic like if (User.IsInRole(“moderator”)) …