Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #21031

CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin.

From Richard Maher <maher_rjSPAMLESS@hotmail.com>
Newsgroups comp.lang.javascript, microsoft.public.dotnet.languages.csharp
Subject CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin.
Date 2013-08-22 20:57 +0800
Organization Aioe.org NNTP Server
Message-ID <kv51rn$ci4$1@speranza.aioe.org> (permalink)

Cross-posted to 2 groups.

Show all headers | View raw


Hi,

Can someone please help me with this error: -
In Load labstats.html:77
GET http://1.2.3.4:2753/LoadCustomerAndDisplay/LibraryJson 400 (Bad 
Request) labstats.html:112

XMLHttpRequest cannot load 
http://1.2.3.4:2753/LoadCustomerAndDisplay/LibraryJson. Origin 
http://1.2.3.4 is not allowed by Access-Control-Allow-Origin. 
labstats.html:112

Uncaught NetworkError: A network error occurred. labstats.html:112

------------------------------------------------------------------------

I'm guessing this is a server-side issue only but in case there are any 
request headers that need to be tweaked in the JS Ajax call I have 
posted to c.l.js and attached the web-page et al at the bottom.

I am launching a debugging session of my C# class library that contains 
an MVC controller that will proxy/redirect a query behind the firewall 
to a URL that is not visible to the outside world.

This is just (hopefully) Mickey-Mouse debugging while I play with 
geolocation.  I want to wander around with my phone and hook-up to my 
PC's VisualStudio debug server. Can I do it?

I've seen that only localhost/127.0.0.1 is the only thing that can 
connect to an IIS debug server but I read about setting IIS Express : -

http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx

But still no joy :-(

Here's the method on my MVC Controller that is AJAXed cross-site from 
the browser: -

        public String LibraryJson()

         {

             Response.AppendHeader("Access-Control-Allow-Origin", "*");



             HttpWebRequest request = 
(HttpWebRequest)WebRequest.Create("http://not.publicly.available/Availability/LibraryJson");

             try

             {

                 WebResponse response = request.GetResponse();

                 using (Stream responseStream = 
response.GetResponseStream())

                 {

                     StreamReader reader = new 
StreamReader(responseStream, Encoding.UTF8);

                     return reader.ReadToEnd();

                 }

             }

             catch (WebException ex)

             {

                 WebResponse errorResponse = ex.Response;

                 using (Stream responseStream = 
errorResponse.GetResponseStream())

                 {

                     StreamReader reader = new 
StreamReader(responseStream, Encoding.GetEncoding("utf-8"));

                     String errorText = reader.ReadToEnd();

                     // log errorText

                 }

                 throw;

             }

         }

The Web.Config

     <httpProtocol>

       <customHeaders>

         <add name="Access-Control-Allow-Origin" value="*" />

         <add name="Access-Control-Allow-Headers" value="Content-Type" />

         <add name="Access-Control-Allow-Methods" value="GET, POST, PUT, 
DELETE, OPTIONS" />

       </customHeaders>

     </httpProtocol>





Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin. Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2013-08-22 20:57 +0800
  Re: CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2013-08-23 15:45 -0700
    Re: CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin. Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2013-08-30 18:16 +0800
    Re: CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-31 11:24 +0200

csiph-web