[英]How to download multiple files? Getting “Server cannot clear headers after HTTP headers have been sent.”
[英]“Cannot redirect after HTTP headers have been sent.” When returning HttpResponseMessage with HttpStatusCode.Unauthorized
我正在使用新的Web Api测试版并希望返回
HttpResponseMessage<MyObject>(new MyObject{ MyMessage = "Go Away!" }, HttpStatusCode.Unauthorized)
来自我的一个ApiController动作。
表单身份验证劫持响应,崩溃并添加错误"Cannot redirect after HTTP headers have been sent."
这是回复的HTML。
像这样的常规抑制技术不适用于Web Api。
有人找到了解决这个问题的工作吗?
我看过这个论坛帖子 ,人们报告同样的问题,但那里的解决方案不适用于这种情况。 建议的第一个解决方案使用常规抑制技术,该技术不适用于web api。 第二个使用HttpMessageHandler在它到达控制器之前拦截请求,我希望控制器正常触发。
在查看DelegatingHandler
我可以访问HttpResponseMessage
但不知道如何处理它以阻止FormsAuth重定向。
使用Phil Haack的SuppressFormsAuthenticationRedirectModule时我遇到了同样的问题
我设法通过清除服务器的错误来修复它,如下所示
private void OnEndRequest(object source, EventArgs args)
{
var context = (HttpApplication)source;
var response = context.Response;
if (context.Context.Items.Contains(SuppressAuthenticationKey))
{
context.Server.ClearError(); //Clearing server error
response.TrySkipIisCustomErrors = true;
response.ClearContent();
response.StatusCode = 401;
response.RedirectLocation = null;
}
}
嗨,因为这个问题似乎仍然是开放的我想我会指出最新的MVC 4 RC版本现在似乎默认禁用了表单重定向。 我做了一些挖掘,同时回复了这个问题, 阻止了阻止ASP.NET Web API响应的FormsAuthenticationModule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.