Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sign in as Different User in asp.net?

I am trying to implement "Sign in as different user" on windows authentication asp.net web site. I followed this blog Sign in as Different User. Everythig is fine except Cancel button. When user requested for userid/password dialog box. If I hit cancel button. it stays at Access denied page.

But I want redirect IIS access denied 401 page. How to do that?

like image 687
James123 Avatar asked Jun 13 '13 16:06

James123


1 Answers

Handle the Application_EndRequest in the global.asax file. A piece of information from the article linked below (not my code):

protected void Application_EndRequest(Object sender, EventArgs e)
{ 
HttpContext context = HttpContext.Current;
if (context.Response.Status.Substring(0,3).Equals("401"))
 {
  context.Response.ClearContent();
  context.Response.Write("<script language="javascript">" + 
                   "self.location='../login.aspx';</script>");
 } 
}

Take a look here for the full-article

like image 53
Amc Amsterdam - Netherlands Avatar answered Oct 18 '22 17:10

Amc Amsterdam - Netherlands