Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Let say you have Forms authentication enabled ASP.NET app with login form login.aspx and your users are stored in DB. Now you'd like to support both, Forms and Windows authentication. That's what I do:</p> <p>For forms auth I use SQL DB with, let say, Users table. I add to this table new column named WindowsUserName in which I'll save Windows user's name in form COMPUTER\User</p> <p>In login.aspx form I add a method, which will send a response that will shows login window:</p> <pre><code>private void ActivateWindowsLogin() { Response.StatusCode = 401; Response.StatusDescription = "Unauthorized"; Response.End(); } </code></pre> <p>Somewhere I have a link like <code>&lt;a href="login.aspx?use=windows"&gt;Admin&lt;/a&gt;</code></p> <p>In login.aspx Page_Load I have added:</p> <pre><code>if (Request.QueryString["use"] == "windows") { var windowsuser = Request.ServerVariables["LOGON_USER"]; if (windowsuser.Length == 0) ActivateWindowsLogin(); else { // get userId from DB for Windows user that was authenticated by IIS // I use userId in .ASPXAUTH cookie var userId = GetUserIdForWindowsUser(windowsuser); if (userId &gt; 0) //user found { // here we get User object to check roles or other stuff var user = GetApplicationUser(userId); // perform additional checks here and call ActivateWindowsLogin() // to show login again or redirect to access denied page. // If everythig is OK, set cookie and redirect FormsAuthentication.SetAuthCookie(userId.ToString(), false); Response.Redirect(FormsAuthentication.GetRedirectUrl(userId.ToString(), false), true); } else //user not found ActivateWindowsLogin(); } } else { //your Forms auth routine } </code></pre> <p>GetUserIdForWindowsUser and GetApplicationUser are my methods just for sample.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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