Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21031 > unrolled thread
| Started by | Richard Maher <maher_rjSPAMLESS@hotmail.com> |
|---|---|
| First post | 2013-08-22 20:57 +0800 |
| Last post | 2013-08-31 11:24 +0200 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.javascript
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
| From | Richard Maher <maher_rjSPAMLESS@hotmail.com> |
|---|---|
| Date | 2013-08-22 20:57 +0800 |
| Subject | CORS with .NET debugger - XMLHttpRequest cannot load Origin X is not allowed by Access-Control-Allow-Origin. |
| Message-ID | <kv51rn$ci4$1@speranza.aioe.org> |
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>
[toc] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2013-08-23 15:45 -0700 |
| Message-ID | <1eb679e4-18c9-4f8c-8ddd-27090ce789ba@googlegroups.com> |
| In reply to | #21031 |
On Thursday, August 22, 2013 7:57:26 AM UTC-5, Richard Maher wrote:
> 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>
Here is a resource that may help:
<https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS>
Check your headers
[toc] | [prev] | [next] | [standalone]
| From | Richard Maher <maher_rjSPAMLESS@hotmail.com> |
|---|---|
| Date | 2013-08-30 18:16 +0800 |
| Message-ID | <kvprds$dnf$1@speranza.aioe.org> |
| In reply to | #21039 |
On 8/24/2013 6:45 AM, Michael Haufe (TNO) wrote: 8< > Here is a resource that may help: > > <https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS> > > Check your headers > Hi Michael, (Sorry for the delay in responding. Thanks for the useful reference BTW) The headers, at least to me, look peachy. See below. What am I doing wrong? It looks like the instructions from my web.config AND individual method BOTH effected the headers. Sounds good right? Cheers Richard Maher HEADERS>>> Request URL: http://1.2.3.4/JSON/LoadCustomerAndDisplay/LibraryJson 2. Request Method: GET 3. Status Code: 200 OK 4. Request Headersview source 1. Accept: */* 2. Accept-Encoding: gzip,deflate,sdch 3. Accept-Language: en-US,en;q=0.8 4. Connection: keep-alive 5. DNT: 1 6. Host: 1.2.3.4 7. Referer: http://1.2.3.4/Labstats.html 8. User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.57 Safari/537.36 5. Response Headersview source 1. Access-Control-Allow-Headers: Content-Type 2. Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS 3. Access-Control-Allow-Origin: * 4. Access-Control-Allow-Origin: * 5. Cache-Control: private 6. Content-Encoding: gzip 7. Content-Length: 655 8. Content-Type: text/html; charset=utf-8 9. Date: Fri, 30 Aug 2013 08:36:21 GMT 10. Server: Microsoft-IIS/7.5 11. Vary: Accept-Encoding 12. X-AspNet-Version: 4.0.30319 13. X-AspNetMvc-Version: 2.0 14. X-Powered-By: ASP.NET
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2013-08-31 11:24 +0200 |
| Message-ID | <3100282.6jc0cexRMq@PointedEars.de> |
| In reply to | #21039 |
Michael Haufe (TNO) wrote: > [100+ lines of quote] > [6 lines of new content] Here are resources that may help: <http://jibbering.com/faq/notes/posting/#ps1Trim> <http://PointedEars.de/scripts/faq/cljs/notes/posting/#ps1Trim> F'up2 poster -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web