【发布时间】:2015-04-07 13:32:38
【问题描述】:
我开发了一个 httpHandler 来完成我使用 angularJS 的 PDF 下载。在我将服务部分移动到不同的域之前,它工作正常。当我将服务部分移动到与我的 UI AngularJS 应用程序不同的域时,它开始出现以下错误。
XMLHttpRequest 无法加载 http://localhost:57072/DocumentHandler.ashx?Caller=1&token=1。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'http://localhost:54470' 不允许访问。响应的 HTTP 状态代码为 500。
这是我的 HttpHandler 方法。
public void ProcessRequest(HttpContext context)
{
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.AddHeader("Access-Control-Allow-Origin", "*");
response.AppendHeader("Access-Control-Allow-Methods", "OPTIONS,POST,GET");
response.AppendHeader("Access-Control-Allow-Headers", "X-File-Name,X-File-Type,X-File-Size");
response.ContentType = MIMEType.Get(filExtension);
response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
using (FileStream stream = this.Open(filesDirectory + fileName))
{
byte[] buffer = new byte[10240];
int count = 0;
while ((count = stream.Read(buffer, 0, buffer.Length)) > 0)
{
response.OutputStream.Write(buffer, 0, count);
response.Flush();
}
}
}
谁能告诉我这里出了什么问题?
【问题讨论】:
标签: angularjs cross-domain httphandler ashx