If you are using an out of the box template, you don't have to worry about Username, WebSecurity will take care of making sure that its unique. As for Email, this is what i did in my Web Application currently working on.
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
// Attempt to register the user
using (EfDb db = new EfDb())
{
UserProfile userEmail = db.UserProfiles.FirstOrDefault(u => u.Email.ToLower() == model.Email.ToLower());
try
{
// Check if email already exists
if (userEmail == null)
{
var token = WebSecurity.CreateUserAndAccount(
model.UserName,
model.Password,
new
{
model.Email
},
true);
}
ModelState.AddModelError("", ErrorCodeToString(MembershipCreateStatus.DuplicateEmail));
}
catch (MembershipCreateUserException e)
{
ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
}
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
As you can see, Database has nothing to do with validation here. C# code takes care of it. Just make sure that in your ViewModel you have this:
[EmailAddress]
[Required]
[Display(Name = "Email")]
public string Email { get; set; }
In the View
<div class="editor-label">
@Html.LabelFor(model => model.UserName)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.UserName)
@Html.ValidationMessageFor(model => model.UserName)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Email)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Email)
@Html.ValidationMessageFor(model => model.Email)
</div>