Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Nicola Nauwynck 11 posts 76 karma points
    Feb 05, 2015 @ 17:06
    Nicola Nauwynck

    Issue with CORS when posting to web api


    I have a project that runs on Umbraco 7.1.1 and I want to post an object to a webapi in the project.

    The action is located on /umbraco/api/dummyapi/getsearchcontent with the following code

    public dynamic GetSearchCount(Guid token, SearchCountRequest request)
        // here I do some code

    But when I post my object from Angular I get "XMLHttpRequest cannot load *. Invalid HTTP status code 405". The Angular code isn't in the same project.

    Search results on Google tell me that this is an issue with CORS so I have tried different things like:

    I have found that installing this package: should be a solution but it isn't possible because Umbraco uses Microsoft.AspNet.WebApi Version 4.. and this isn't compatible with the earliest version of Microsoft.AspNet.WebApi.Cors.

    Any suggestions on how you got CORS working? Am I missing something or?

  • Yakov Lebski 441 posts 1715 karma points
    Feb 23, 2015 @ 21:33
    Yakov Lebski

    Hi I have the same issue, did you solve it ?

  • Nicola Nauwynck 11 posts 76 karma points
    Feb 24, 2015 @ 08:47
    Nicola Nauwynck

    No I did not solve it but I worked around it.

    I placed the Angular code in the same project so it runs on the same localhost. Now the API and Angular are running on the same host so there are no longer CORS isssues

  • Yakov Lebski 441 posts 1715 karma points
    Feb 24, 2015 @ 10:29
    Yakov Lebski

    I my case I solve it it in 2 step, add in web.config

        <remove name="X-Powered-By" />
        <add name="Access-Control-Allow-Origin" value="*" />
        <add name="Access-Control-Request-Headers" value="*" />

    Other problem is avoid send authorization header in angular request

  • Urvish 252 posts 774 karma points
    Apr 06, 2015 @ 10:46

    Thanks Yakov Lebski for the solution.

    It works for me for simple ajax post.


    Urvish Mandaliya

Please Sign in or register to post replies

Write your reply to: