1
OPTIONS http://localhost:7514/Employees/testrestricted 401 (Unauthorized) angular.js:10419
OPTIONS http://localhost:7514/Employees/testrestricted Origin http://localhost:4064 is not allowed by Access-Control-Allow-Origin. angular.js:10419
XMLHttpRequest cannot load http://localhost:7514/Employees/testrestricted. Origin http://localhost:4064 is not allowed by Access-Control-Allow-Origin. 

I have my app.js setup like this already:

var app = angular.module('angular-auth-demo', ['http-auth-interceptor']);

app.config(['$routeProvider', '$httpProvider', function ($routeProvider, $httpProvider) {

    $httpProvider.defaults.useXDomain = true;
    delete $httpProvider.defaults.headers.common['X-Requested-With'];

    $routeProvider.
        when('/home', { templateUrl: 'partial-content.html', controller: 'ContentController' }).
        otherwise({ redirectTo: '/home' });
}]);

is there a way to find out if this is an error on angular or asp.net mvc, because I have a cors configuration on that end too, but i don't think the browser is actually getting a chance to hit the server?

4
  • Did you found a solution for this? I still cant find way to fix this on post request. Commented Jul 25, 2013 at 13:07
  • @Pnct what seems to be the problem? Combining the two answers fixed the problem for me. Commented Jul 26, 2013 at 4:25
  • Working post request on cross domain? Only GET works on cross domain, dunno why POST is denying :/ OPTIONS api.domain Contact Origin app.domain is not allowed by Access-Control-Allow-Origin. angular.min.js:106 XMLHttpRequest cannot load api.domain/Contact. Origin app.domain is not allowed by Access-Control-Allow-Origin. Commented Jul 26, 2013 at 7:24
  • @Pnct what kind of backend are you running? IIS and MVC I'm assuming? Did you try adding the settings in the second post to your web.config? Commented Jul 26, 2013 at 14:06

3 Answers 3

3

I had a similar issue using Font Awesome cross domain - specifically with Firefox.

Adding a web.config in the directly with the resource you need to access with this solved it for me.

 <configuration>
    <system.webServer>
        <httpProtocol>
          <customHeaders>
            <add name="Access-Control-Allow-Origin" value="*" />
          </customHeaders>
       </httpProtocol>
   </system.webServer>
</configuration>
Sign up to request clarification or add additional context in comments.

Comments

1

The request is getting to the server because the server is returning a 401. See the network tab in Chrome dev tools or Firebug. Assuming you have the Access-Control-Allow-Origin header already, you probably need to specify the Access-Control-Allow-Headers header and add Content-Type as its value. Maybe post your CORS config/code?

Comments

0

following solution worked for be: http://forums.asp.net/t/1885459.aspx

protected void Application_BeginRequest(object sender, EventArgs e)
        {
            if (this.Context.Request.Path.Contains("signalr/negotiate"))
            {
                this.Context.Response.AddHeader("Access-Control-Allow-Origin", "*");
                this.Context.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
                this.Context.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST");
                this.Context.Response.AddHeader("Access-Control-Allow-Credentials", "true");
            }
        }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.