Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Like you said <code>User.Identity.Name</code> is indeed correct. for returning the logged in users name. But the membership section like you said, provides only windows accounts. You can use similar without the user of windows accounts, to work in every scenario, and can still verify against windows if present. If you call it without membership, and follow the default MVC3 template it should work fine.</p> <pre><code>String Username = User.Identity.Name; </code></pre> <p>When you log on, using the template MVC3, it creates an <code>authcookie</code>. <em>See account controller code</em>. Here, two parameters are passed into it. The username, and to persist (when browser is closed - login is still cached).</p> <p>The username is a string field, which is what is called by <code>User.Identity.Name</code> and infact, anything can be put into it, and is not in anyway linked to Windows login.</p> <p>You could test the login via method you desire, and if yes, set a cookie using the authcookie method. (its encripted). And set the username to what ever you want. And if your verification of the user fails, dont create one, and redrect back to page.</p> <p>See the example code. This is all from memory, as I dont have code infront of me for reference. But its all in the account controller, Login Action.</p> <p>When the cookie is set, The users login state is cached for the session. You will need to ensure the user is logged in when visiting a webpage. Otherwise loggin in will be pointless. This is a simple attribute on the controller/action. </p> <p>Note: dont do this to the Account/logon controller, as you wont be able to visit the logon page, as you are not logged in.</p> <pre><code>[Authorize] public ActionResult DoSomething() { // ... } </code></pre> <p>Hope I have helped.</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