Windows ASP.NET Authentication Output

How do you log out when using Windows authentication in ASP.NET like this web.config?

<authentication mode="Windows" /> 

I have already tried the following unsuccessfully. It redirects but does not log out.

 void logoutButton_Click(object sender, EventArgs e) { HttpContext.Current.Session.Clear(); HttpContext.Current.Session.Abandon(); ViewState.Clear(); FormsAuthentication.SignOut(); Response.Redirect("/"); } 

Reference Information:

I need to use Windows authentication because I need to personalize my identity using Active Directory in order to access local files. And I can't pretend to use Forms authentication because HttpContext.Current.User.Identity will not be WindowsIdentity . Pretend to use forms authentication

+42
logout windows-authentication
Jul 01 '09 at 4:23
source share
6 answers

When using Windows authentication, the server exit button will not work. You must use "Forms" authentication if you want to log out or close the user's browser.

+27
09 Oct '09 at 19:11
source share

For IE browsers only, you can use the following javascript to log out a user if using Windows Authentication. (Note: closing the browser is not required, but recommended, as the user can use a browser that is not IE).

If the user clicks “No” to close the browser, the user will be asked to enter a username / password if they try to access a page on a site that requires authentication.

 try { document.execCommand("ClearAuthenticationCache"); } catch (e) { } window.close(); 

This code was taken from the SharePoint Signout.aspx page.

+19
Apr 20 2018-11-11T00:
source share

Windows authentication works at the IIS level, passing the Windows authentication token. Since authentication takes place at the IIS level, you cannot actually exit the application code. However, there seems to be an answer to your problem here . This is the second issue that is being addressed and essentially involves the use of forms authentication and api. LogonUser Windows.

+11
Jul 01 '09 at 5:09
source share

I had a SharePoint application with Windows authentication, I had to log out automatically after 15 minutes. I mixed up some codes, and here is the result. It works in IE correctly.

 <script type="text/javascript"> var t; window.onload = resetTimer; document.onmousemove = resetTimer; document.onkeypress = resetTimer; function logout() { try { document.execCommand("ClearAuthenticationCache"); window.location.href = window.location.protocol.replace(/\:/g, '') + "://" + window.location.host + "/_layouts/customlogin14.aspx"; } catch (e) { } } function resetTimer() { window.clearTimeout(t); t = window.setTimeout(logout, 900000); } 

put these codes on your main page, after 15 minutes of inactivity you will see the login page. hope this help someone

+6
Jun 10 '13 at 19:27
source share

I have work using JavaScript in IE and Firefox, although it registers you from everything that you are logged into IE. This works in Safari, but Safari displays a phishing alert. Doesn't work in Opera.

 try { if (document.all) { document.execCommand("ClearAuthenticationCache"); window.location = "/"; } else { window.location = "http://logout:logout@example.com"; } } catch(e) { alert("It was not possible to clear your credentials from browser cache. Please, close your browser window to ensure that you are completely logout of system."); self.close(); } 
+3
Jun 17 '11 at 16:59
source share

The best answers I've seen are found in StackOverFlow related questions:

Is there a browser equivalent to ClearAuthenticationCache IE?

and

Logging with Basic HTTP Authentication

Basically, you need to send an AJAX request to the server with invalid credentials and accept the server.

+1
Dec 14 '11 at 15:06
source share



All Articles