Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Unless i'm misunderstanding the question...</p> <p>Those models are concerned with the User <strong>model</strong>.</p> <p>UserId and Roles are dealing with <strong>authentication and authorization</strong>.</p> <p>Most likely, you are using Forms Authentication and the default ASP.NET Membership provider.</p> <p>If you want to access the UserId of the current logged in user, you need to add it to the forms authentication ticket when you sign the user in, then you can access it via <code>HttpContext.Current.Request.User.Identity</code>.</p> <p>If your using <code>FormsAuthentication.SetAuthCookie</code>, then <code>Identity.Name</code> will point to whatever you passed to <code>SetAuthCookie</code> - so you could pass the UserId.</p> <p>But most people (myself included), use nicknames/usernames for the <code>Identity.Name</code>, so you need to create the Forms Authentication ticket manually and add it to the response cookies.</p> <p>To see if a user is in a role, do this:</p> <p><code>HttpContext.Current.User.IsInRole("Administrator")</code></p> <p>This is standard ASP.NET stuff, not specific to ASP.NET MVC.</p> <p>Also, if your using an ORM like Entity Framework or NHibernate or Linq2Sql, don't map the membership tables.</p> <p>Create your own User table which has a FK pointing to that table, then your User table becomes the model.</p> <p>The built in membership provider API will use stored procedures behind the scenes to perform the functionality you require.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload