2

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.

2
  • Where are you stucked exactly ? What did you tried yet as source code ? Commented Jan 30, 2014 at 9:35
  • not sure who is up voting this because it is not a well formed question: see here stackoverflow.com/questions/how-to-ask Commented Jan 30, 2014 at 9:41

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.