简体   繁体   中英

Forms authentication in asp.net mvc 3 - ActionResult Register method - how to?

can you please help me. I have written logon and logout methods correctly using forms authentication in asp.net mvc 3.

[HttpPost]
public ActionResult LogOn(Guest guest, String returnURL, bool RememberMe = false)
{
    var isValidURL = bl.IsValidReturnUrl(returnURL);

    if (!ModelState.IsValid)
    {
        ModelState.AddModelError("", "The username or password provider is incorrect");
        return View(guest);
    }

    if (bl.IsUserValidated(guest.Username, guest.Password))
    {
        FormsAuthentication.SetAuthCookie(guest.Username, RememberMe);
        if (isValidURL)
            return Redirect(returnURL);
        else
            return RedirectToAction("Home", "Index");
    }
    return View(guest);
}

How to write a Register controller method, I don't know where to start, I have my own database in which I should insert new registered users with their username, password and email. Thanks

In general you get their registration details (at the very least username and password, but best also email) and send it back to the register action.

Check that the username and password match your criteria. Then, check for duplicate users. If there aren't, you register to the database and inform them that they are registered.

You should really register their account as inactive at first, and send them an email with an activation link. When they access the link, have your action set the account to active and inform them that now they can use the website.

Does that help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM