我的WebApi项目中有一个slice
处理程序。源代码可用here。我试图从我的AngularJs项目中调用我的处理程序。这是代码:
_invoice_pdf.html.erb
HTML
ImageUploadHandler.ashx
调用此处理程序时出现404错误,这是错误快照:
答案 0 :(得分:0)
这就是诀窍:
public void ProcessRequest(HttpContext context)
{
context.Response.ClearHeaders();
string origin = context.Request.Headers["Origin"];
context.Response.AppendHeader("Access-Control-Allow-Origin",
string.IsNullOrEmpty(origin) ? "*" : origin);
string requestHeaders = context.Request.Headers["Access-Control-Request-Headers"];
context.Response.AppendHeader("Access-Control-Allow-Headers",
string.IsNullOrEmpty(requestHeaders) ? "*" : requestHeaders);
context.Response.AppendHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
}
另外,我必须在web.config
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true">
</modules>
<handlers>
<add name="ImageUploadHandler" verb="*" path="ImageUploadHandler.ashx" type="JetAdz.WebApi.ImageUploadHandler, JetAdz.WebApi, Version=1.0.0.0, Culture=neutral" />
</handlers>
</system.webServer>