R
Richard Maher
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>
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>