asp.net - 防止 ASP.NET 重定向到 login.aspx

标签 asp.net asp.net-mvc .htaccess angularjs

我们有一个完全在 AngularJS 上运行的网站,带有 ASP.NET Web API 后端,配置如下:
- 在 Angular 上启用了 HTML5 路由,并且在 web.config 中有一个重写规则将所有流量定向到 index.html
- 未安装 MVC(仅 Razor 页面)
- 使用表单例份验证和相关 cookie 进行身份验证

我刚刚添加了 Helicon IIS 插件,以便为我们的开发服务器保护 .htaccess 密码(单独使用 IIS 是一团糟),但我有一个基本问题。

输入基本身份验证凭据后,我将重定向到 /login.aspx?ReturnUrl=虽然我不确定谁对此负责(IIS 或 Helicon 插件),但它会匹配我的 AngularJS 路由之一并导致错误。

我怎样才能阻止这种重定向的发生?

我的 web.config 身份验证位:

<authentication mode="Forms">
  <forms protection="All" timeout="15" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="false" cookieless="UseCookies" enableCrossAppRedirects="false" />
</authentication>

最佳答案

如果您使用的是 ASP.NET 4.5。
您可以禁用表单例份验证重定向
HttpResponse.SuppressFormsAuthenticationRedirect 属性。

在 Global.asax 中:

protected void Application_BeginRequest(Object sender, EventArgs e)
{
        HttpApplication context = (HttpApplication)sender;
        context.Response.SuppressFormsAuthenticationRedirect = true;
}

关于asp.net - 防止 ASP.NET 重定向到 login.aspx,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18519446/

相关文章:

c# - 抛出新的 ArgumentException

c# - HttpContext.Current.Request.Files 始终为空

asp.net-mvc - Visual Studio : The system cannot find the path specified

c# - mvc5 razor 向 Controller 发送参数

php - Concrete5 在系统页面上强制使用 SSL

regex - .htaccess 301 重定向,保留路径

php - 以 seo 友好的方式重写 htaccess 中的复杂 url

javascript - 如何在选项选择上使用 jquery 自动完成引起回发?

c# - 使用函数检查 Eval()

c# - 如何操作 Html.ActionLink 以显示到另一个 Controller 的链接?