I want to add a user's GUID in with the information I retrieve from a user when they submit a post. How can I get the GUID?
I am using the default authentication system that comes along with an ASP.NET MVC application.
If you are using the ASP.NET Membership provider:
MembershipUser user = Membership.GetUser(User.Identity.Name);
Guid guid = (Guid)user.ProviderUserKey;
or simply:
Guid guid = (Guid)Membership.GetUser().ProviderUserKey;
You could simply use the username instead of hitting the database for something like this:
[Authorize]
public ActionResult PostComment()
{
var username = User.Identity.Name;
// Here you know the user trying to post a comment
...
}
Hi there is a MVC use of the Membership example, with explanation in this blog. It shows how you can get the membership information of current logged in user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With