Skip to content

Instantly share code, notes, and snippets.

@koistya
Created June 19, 2012 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koistya/2956368 to your computer and use it in GitHub Desktop.
Save koistya/2956368 to your computer and use it in GitHub Desktop.
Membership service usage sample inside ASP.NET MVC controller
public class AccountController : Controller
{
private readonly IMembershipService membershipService;
// service initialization is handled by IoC container
public AccountController(IMembershipService membershipService)
{
this.membershipService = membershipService;
}
// .. some other stuff ..
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (this.ModelSteate.IsValid)
{
// then passes it to the service method and checks for errors
// which returns ServiceResponse<User> with the status of operation and registered user entity
var response = this.membershipService.CreateUser(model);
if (response.Success)
{
FormsAuthentication.SetAuthCookie(response.Value.UserName, createPersistentCookie: false);
return RedirectToAction("Index", "Home");
}
response.Errors.CopyTo(this.ModelState);
}
return View();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment