Handle windows authentication login popups Cancel click

丶灬走出姿态 提交于 2019-12-12 01:52:55

问题


I have simple web application called App that is secured with Windows Authentication. I have set identity impersonate to true in web.config. There is only one page (Default.aspx) in App directory. When user enters the site ex.: http://localhost/App the login window pops up. When user clicks Cancel, IIS redirects to page with an error 401.2. I want to redirect to http://localhost/App/app_start/login.aspx. App_start is an aplication that is secured with Forms Authentication. I tried to handle programmatically the redirection by adding Application_EndRequest method in Global.asax file. But when user clicks Cancel the Application_EndRequest is not being fired. When user successfully logs in the method is being fired. Is there any way to handle error 401.2 programmatically or maybe in a different way?

Application_EndRequest code:

if (Response.StatusCode == 401)

{

 Response.Clear();

 Response.Write("You don't have access to content.");

}

The web.config file of App application:

Thanks for help.

Sincerely,

Peter.


回答1:


You should be able to set the 401.2 error in IIS to be redirected to a URL instead of a file. If you do this just set the 401.2 redirect to your other web application and that should work.

Right Click on the site in iis, properties, custom errors.



来源:https://stackoverflow.com/questions/4085269/handle-windows-authentication-login-popups-cancel-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!