I'm creating one asp.net mvc 4.0 application. in which I want to use default asp.net form authentication. I've created all required tables in ms sql for storing roles and username password.
help me earliest possible. I'm stuck at this point.
I'm creating one asp.net mvc 4.0 application. in which I want to use default asp.net form authentication. I've created all required tables in ms sql for storing roles and username password.
help me earliest possible. I'm stuck at this point.
if you are using asp.net mvc 4.0 form authentication with required tables in mssql server. you can create new user as follows.
[AllowAnonymous]
public JsonResult RegisterUser()
{
String Uid = Request.QueryString["id"];
String Pass = Request.QueryString["pass"];
String username = Uid;
String password = Pass;
try
{
//Session["username"] = username;
Membership.CreateUser(Uid, Pass);
return Json("success", JsonRequestBehavior.AllowGet);
}
catch(Exception e)
{
return Json("falied", JsonRequestBehavior.AllowGet);
}
}
and you can validate the user in the same as follows.
[AllowAnonymous]
public JsonResult ValidateUser()
{
String Uid = Request.QueryString["id"];
String Pass = Request.QueryString["pass"];
String username = Uid;
String password = Pass;
if (Membership.ValidateUser(username, password))
{
//Session["username"] = username;
FormsAuthentication.RedirectFromLoginPage(username, true);
return Json("success", JsonRequestBehavior.AllowGet);
}
else
{
return Json("falied", JsonRequestBehavior.AllowGet);
}
}
Hope this will help you.