ASP.net WEB API CORS 404 error

前端 未结 1 1873
孤独总比滥情好
孤独总比滥情好 2020-12-22 03:12

I create a Windows Service with a integrated ASP.net Host and WEB API. The host and API works fine. When I use my internet Browser I get response from my controller, so no p

相关标签:
1条回答
  • 2020-12-22 03:39

    I think your cors configuration is not correct. Web client and web api connections are different so I understand your problem.

    I'm writing our configuration below so you can check it.

    ASP.NET (OWIN)

    Install-Package Microsoft.Owin.Cors -Version 3.1.0
    

    Startup.cs:

    app.UseCors(CorsOptions.AllowAll)
    

    Web Config:

    <system.webServer>
      <handlers>
        <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
        <remove name="OPTIONSVerbHandler" />
        <remove name="TRACEVerbHandler" />
        <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      </handlers>
    </system.webServer>
    

    ASP.NET (System.Web)

    Install-Package Microsoft.AspNet.WebApi.Cors
    

    App_Start/WebApiConfig - Register method:

    config.EnableCors();
    

    FooController:

    [EnableCors(origins: "*", headers: "*", methods: "*")]
    
    0 讨论(0)
提交回复
热议问题