处理 Windows 身份验证登录弹出窗口 取消单击

发布于 2024-09-30 13:38:35 字数 837 浏览 0 评论 0原文

我有一个名为 App 的简单 Web 应用程序,它通过 Windows 身份验证进行保护。我已在 web.config 中将身份模拟设置为 true。 App目录下只有一页(Default.aspx)。当用户输入网站例如: http://localhost/App 时,会弹出登录窗口。当用户单击“取消”时,IIS 重定向到错误 401.2 的页面。我想重定向到 http://localhost/App/app_start/login.aspx。 App_start 是一个使用表单身份验证保护安全的应用程序。我尝试通过在 Global.asax 文件中添加 Application_EndRequest 方法以编程方式处理重定向。但是,当用户单击取消时,Application_EndRequest 不会被触发。当用户成功登录时,该方法将被触发。有没有办法以编程方式或以不同的方式处理错误 401.2?

Application_EndRequest代码:

if (Response.StatusCode == 401)

{

 Response.Clear();

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

}

App应用程序的web.config文件:

感谢您的帮助。

此致,

彼得。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

诗化ㄋ丶相逢 2024-10-07 13:38:35

您应该能够将 IIS 中的 401.2 错误设置为重定向到 URL 而不是文件。如果您这样做,只需将 401.2 重定向设置为您的其他 Web 应用程序,就可以了。

右键单击iis中的站点,属性,自定义错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文