Downloading files to remote server HTTP 400 error - c#

Program uses DownloadString function of Web.Client.
The url's I have tried so far:
http://xxx.xxx.x.xx/blabla.ashx?command=blabla - Http 404
http://xxx.xxx.x.xx:port/blabla.ashx?command=blabla - Http 400
When I type
http://xxx.xxx.x.xx
IIS page shows up as expected.

Problem solved now. It seems you have to add a binding to IIS to use an address in remote machine.

Related

Unreachable endpoint from Azure

I am trying to reach an endpoint hosting a json from an Azure function.
I can access the url from my machine in a browser or when executing the code.
But from Azure I keep getting a 406.
the code is pretty simple and as follow:
var client = new HttpClient();
client.DefaultRequestHeaders
.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await client.GetAsync(endpointurl);
response.EnsureSuccessStatusCode();
this keeps giving me the 406 when hosted on Azure, not on local ...
Any idea how to get more information? How to debug/fix that?
Thanks
406 is one of the HTTP Response Status codes which indicates that something is NOT ACCEPTABLE.
From you code we are requesting something with Accept header, but the server is unable to fulfill it.
Also, as 406 will comes under 4XX which is client error responses.
In our case, we are requesting a specific content type to be returned by the server. For ex: Accept: application/json or application/xml, so here server is unable to respond to the matching content type that was requested. This leads to throwing a 406 Not Acceptable error.
Most possible situation of cause the error is with the endpoint URL and it show have access to it. As you mentioned that it is working on local, there should be some parameters assigning. Like adding connections like local.settings.json to Application settings in Azure portal, CORS to your endpoint..
Check for private endpoint info from MS Docs
To understand more about 406 Not Acceptable Error refer to blog, thanks to airbrake.io

Why specific response codes are being replaced by 500 Internal Server Error in Production environment?

In my .Net Core 2.2 application, I have a WebAPI controller that may return response codes 400 and 409.
In the development environment, I can see those codes along with the error messages. But when I deploy the application to the production environment (a virtual machine in Azure) I see just 500 errors without any details. Can anybody explain how to force IIS to return the initially sent error responds?
I return the error responds with the code like the following:
return StatusCode((int)HttpStatusCode.BadRequest, new { Message = errorMessage });
Finally, I have turned on the Failed requests tracing and it gave me a clue. The cause was in the fact that the same MIME type was configured twice, one time globally at the IIS level, and the second time at the website level. Once I removed the problematic MIME-type from the website configuration all started working correctly.
If someone have the same problem, I solved in the Error Pages area from IIS configuration. When I tried to click, I received a error with the path of web.config from another project. When I solved this error from web.config, the Error Page open correctly and everything work again.

Unable to view stylesheet in chrome

Tried to run http://localhost:30832/stylesheet/login.css but it returned
This localhost page can’t be found No webpage was found for the web
address: http://localhost:30832/stylesheet/login.css HTTP ERROR 404
What is happening? I am very sure the naming is correct and it exists.

FiddlerCore behavior when network is disconnected

I'm handling local requests by using FiddlerCore like this:
private static void FiddlerApplication_BeforeRequest(Session session)
{
if (session.hostname.ToLower() == "localhost")
ProcessRequest(session);
}
Everything works well but when the Internet network is down, I'm getting the following message:
"[Fiddler] DNS Lookup for "www.google.com" failed. The system reports that no network connection is available. No such host is known"
My question is:
How should I configure FiddlerCore so when the network is down, I will receive the regular 404 page?
You're noting: When a proxy is present, the browser doesn't show its default error pages. That is a correct statement, and it's not unique to Fiddler.
You're confusing folks because you're talking about "regular 404 response"s. That's confusing because the page you're talking about has nothing to do with a HTTP/404-- it's the browser's DNS Lookup Failure or Server Unreachable error page, which it shows when a DNS lookup fails or a TCP/IP connection attempt fails. Neither one of those is a 404, which is an error code that can be returned by a server only after the DNS lookup succeeds and the TCP/IP connection is successful.
To your question of: How can I make a request through a proxy result in the same error page that would be shown if the proxy weren't present, the answer is that, in general, you can't. You could do something goofy like copying the HTML out of the browser's error page and having the proxy return that, but because each browser (and version) may use different error pages, your ruse would be easily detectable.
One thing you could try is to make a given site bypass the proxy (such that the proxy is only used for the hosts you care about). To do that, you'd create a Proxy Autoconfiguration script file (a PAC file) and have its FindProxyForURL function return DIRECT for everything except the site(s) you want to have go through the proxy. see the Configuration Script section of this post.
But, stepping back a bit, do you even need a proxy at all? Can't you just run your web server on localhost? When you startup Fiddler/FiddlerCore, it listens on localhost:[port]. Just direct your HTTP request there without setting Fiddler as the system proxy.

Does ASP.NET Custom Errors override the actual HTTP response code?

If I were to specify a page for redirect using the ASP.NET Custom Errors feature, would my application still spit out the HTTP status code for that particular error?
For example if had a line in my web.config that had all Internal Server Errors redirect to Errors/500.aspx and then I encountered a 500 error, I would then be redirected to my custom Errors/500.aspx page. Will my application still respond with a HTTP 500 at any point in this exchange?
I'm just curious...
No, because your browser would interpret that 500 response as an error and show you it's error. Instead, it probably responds with one of the redirect status codes to send you to the defined error page.

Categories

Resources