c# - 在 asp.net 中以不同用户身份登录?

标签 c# asp.net iis windows-authentication

我正在尝试在 Windows 身份验证 asp.net 网站上实现“以不同用户身份登录”。 我关注了这个博客 Sign in as Different User .除 Cancel 按钮外,一切正常。 当用户请求用户 ID/密码对话框时。如果我点击 cancel 按钮。它停留在 Access denied 页面。

但我想重定向 IIS 访问被拒绝的 401 页面。如何做到这一点?

最佳答案

处理 global.asax 文件中的 Application_EndRequest。下面链接的文章中的一条信息(不是我的代码):

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>");
 } 
}

拍一个look here对于全文

关于c# - 在 asp.net 中以不同用户身份登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17092450/

相关文章:

url - 错误状态: URL contains outer http

c# - ASP.NET Core错误:System.TypeLoadException:无法加载类型 'Microsoft.AspNetCore.WebUtilities.FileBufferingWriteStream'

ASP.NET - 设计者和开发者之间的协作

asp.net - 检查表单是否具有 key ?

iis - 如何允许匿名访问 IIS 7.5 上的网站?

php - cakephp 缓存文件夹在 iis 上不可写

c# - GUI 在代码完成之前不更新

c# - 从多个线程读取SQL数据

c# - 减少 C# 中的代码冗余

javascript - 使用 window.open 仅打开 url 的一个实例