要解决这个问题,可以使用以下代码示例:
在Global.asax.cs文件中,添加以下代码:
protected void Application_BeginRequest()
{
// 仅在第一个请求时启用Windows身份验证
if (Request.Url.AbsolutePath.EndsWith(".css") || Request.Url.AbsolutePath.EndsWith(".js"))
{
// 启用Windows身份验证
HttpContext.Current.Response.AddHeader("WWW-Authenticate", "Negotiate");
HttpContext.Current.Response.AddHeader("WWW-Authenticate", "NTLM");
HttpContext.Current.Response.StatusCode = 401;
HttpContext.Current.Response.End();
}
}
上述代码在每个请求开始时进行检查,如果请求的文件是.css或.js文件,则会启用Windows身份验证。通过添加相应的WWW-Authenticate头和401状态码,强制浏览器在后续请求中提供Windows凭据。
请注意,这只是一个示例代码,你可能需要根据你的具体情况进行适当的修改和调整。