asp.net mvc 3 - Add User Roles on Registration (Forms Authentication) MVC3 -
I am developing an MVC 3 project and want to add a registered user to a role using form authentication. I am That's why I want to make some check boxes, or show roles in a drop down list, which are selected and the user has been registered as a role.
I still have this code, which works:
Public Action Register () {View Data ["Roleplay"] = New Selection List (Roles.GetAilroll () , "Role-name"); See Return (); } And in this view I have:
This is the HPPOST section of the controller, and this is the part that I do not know the code:
[http post] Public Action Result Register (Register Modell Model) {if (ModelState.IsValid) {// Try to register user membershipStats vsstats; Membership Buyer user (model user name, model password, model email, blank, empty, true, empty, outdoors); If (createStatus == subscribe) stability) {form attestation.SetAuthCookie (model.UserName, false / * createPersistentCookie * /); Redirect Action ("Index", "Home"); } Other {ModelState.AddModelError ("", ErrorCodeToString (createStatus)); }} // If we got this far away, then some failed, see the form return view (model); In this way, all roles are visible in the scene.
Thanks a lot, Amy
Itemprop = "text">
If (createStatus == be sure to subscribe.) Success) {roles. AddUserToRole (model.UserName, "RoleName"); FormAuthentication.SetAuthCookie (Model username, false / * createentcentant cookie * /); Redirect Action ("Index", "Home"); } Try this should work
Comments
Post a Comment