I am using SQL Server and WebMatrix Razor syntax to try and determine is a username is contained within a table called Users.
The logic I wish to have is :
bool usernameExists = db.QueryValue("SELECT Username from Users where Username = ?", username);
if(usernameExists.IsEmpty()){ //username is not in table
Response.Redirect("Register.cshtml");
}
What is the best practice for going about this?
One approach would be to implement a custom membership provider which authenticates against your own user table. You application is then decoupled from the specifics of user storage and it's a well understood model for user authentication in ASP.NET applications.
Simplest is probably:
Though I'm speaking strictly from the SQL Server side. I don't know if this is the best approach from the C# side.