Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 26, 2012 02:09 AM by richkyrs
Member
106 Points
59 Posts
Jan 23, 2012 05:26 PM|LINK
JohnLocke If you have a username column in your table... var profile = db.Profiles.Single(p => p.username == User.Identity.Name); then profile object will inherit all the values of Profiles table for that username var currentUserId = profile.UserId;
If you have a username column in your table...
var profile = db.Profiles.Single(p => p.username == User.Identity.Name);
then profile object will inherit all the values of Profiles table for that username
var currentUserId = profile.UserId;
Thank you, that's a good solution as well...
436 Points
500 Posts
May 26, 2012 02:09 AM|LINK
public ActionResult Verify(string id) { if (string.IsNullOrEmpty(id) || (!Regex.IsMatch(id, @"[0-9a-f]{8}\- ([0-9a-f]{4}\-){3}[0-9a-f]{12}"))) { ViewBag.Msg = "Not Good!!!"; return View(); } else { var user = Membership.GetUser(new Guid(id)); if (!user.IsApproved) { user.IsApproved = true; Membership.UpdateUser(user); FormsAuthentication.SetAuthCookie(user.UserName, false); return RedirectToAction("Index", "Home"); } else { FormsAuthentication.SignOut(); ViewBag.Msg = "Account Already Approved"; return RedirectToAction("LogOn"); } } }
webwired72
Member
106 Points
59 Posts
Re: How to reference MVC 3 built-in Account UserId
Jan 23, 2012 05:26 PM|LINK
Thank you, that's a good solution as well...
richkyrs
Member
436 Points
500 Posts
Re: How to reference MVC 3 built-in Account UserId
May 26, 2012 02:09 AM|LINK
public ActionResult Verify(string id)
{
if (string.IsNullOrEmpty(id) || (!Regex.IsMatch(id, @"[0-9a-f]{8}\-
([0-9a-f]{4}\-){3}[0-9a-f]{12}")))
{
ViewBag.Msg = "Not Good!!!";
return View();
}
else
{
var user = Membership.GetUser(new Guid(id));
if (!user.IsApproved)
{
user.IsApproved = true;
Membership.UpdateUser(user);
FormsAuthentication.SetAuthCookie(user.UserName, false);
return RedirectToAction("Index", "Home");
}
else
{
FormsAuthentication.SignOut();
ViewBag.Msg = "Account Already Approved";
return RedirectToAction("LogOn");
}
}
}