Solved

How to logout of ASP.net website when Basic authentication is used for authentication at login?

Posted on 2013-11-06
2
814 Views
Last Modified: 2013-11-11
How to logout of ASP.net website when Basic authentication is used for authentication at login?
0
Comment
Question by:Raj_donet
2 Comments
 
LVL 40

Assisted Solution

by:Kyle Abrahams
Kyle Abrahams earned 250 total points
ID: 39628667
<competing site link removed - GaryC13>

Create a "/logout" page on your server which accepts only a certain credential such as username: false, password: false. Then using this AJAX request below, you can send the user to that page.


 $("#logout").click(function(e){                                              
    e.preventDefault();                                                        
    var request = new XMLHttpRequest();                                        
    request.open("get", "/logout", false, "false", "false");                                                                                                                               
    request.send();                                                            
    window.location.replace("WHEREVER YOU WANT YOUR LOGGED OUT USER TO GO");                                              
  });

Open in new window


The other thing you can do is just force the browser closed.  

<a href="javascript:window.opener='x';window.close();">Logout</a>
0
 
LVL 15

Accepted Solution

by:
pateljitu earned 250 total points
ID: 39628675
Once the user is logged in create a "Logout" link which when clicked take you to logout.aspx page, on page_load of logout.aspx.cs page add sample as provided and user will be prompted to windows authentication
protected void Page_Load(object sender, EventArgs e)
        {
            // Create a 401 response
            Response.Buffer = true;
            Response.StatusCode = 401;
            Response.StatusDescription = "Unauthorized";

            // A authentication header must be supplied. This header can be changed to Negotiate when using keberos authentication
            Response.AddHeader("WWW-Authenticate", "NTLM");

            // Send the 401 response
            Response.End();
        }

Open in new window

0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question