That depends on what type of Login service you're providing. If you're providing the default
WebSecurity
service. Then you can simply just search inside the Database table and get the results. For example
var db = Database.Open("DatabaseName");
var searchQuery = "SELECT * FROM UserProfile WHERE LOWER(Username) = LOWER(@0)";
var results = db.Query(searchQuery, username);
..now results would contain an enumeration. That would have the rows that were returned. Obviously there will be one row returned if there is a match. If there is no match then no result would be returned. You can see that using this code block.
if(results.Count > 0) {
<div>Sorry, this username is being used.</div>
} else {
}
As I have said, it depends on your requirements.
Code example from ASP.NET Team
If you're using WebMatrix or Visual Studio you can create a new website and then go to the Accounts -> Register.cshtml page there you can see the usage of this process. They search for a user with the email address specified and then if the result is zero. They continue the process otherwise show an error saying email already exists.
StarterSite ASP.NET template for Web Pages has this functionality.
You don't need to be having a jQuery or JavaScript ajax request just to check. You can do this job on a simple HTTP POST or GET request too. You just need to search for the data inside your database and if no data is returned from SQL, username is available, if there is a result then the username is already taken.