我们有一个完全在 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/