Accessing web resources using .NET's WebRequest class is such a common task that it is almost a given that it should qualify "write once and run everywhere". Yet, it does not. A simple code block to make HTTP requests start to fail as soon as it is moved to a non-dev machine :).
Almost all of the cases end up being related to the way HTTP proxies have been configured in a different environment and that the machines can not be make HTTP requests without going to proxy. The situation becomes grimmer when there are tricky configurations like URL1 is allowed to be accessed without proxy and URL2 is not allowed to be accessed without proxy. The mire!!
So what do we do in such cases?
1. If all the traffic is allowed through proxy then you can simply update the config file of the application with defaultProxy/Proxy element.
2. If there is a list of URLs that need to be bypassed, then additional element needs to be added.
Where do we add this entries?
Go in this order:
1. If it is for just one application, use configuration file of the application.
2. If it is to be done for all applications on the machine
- If it is a desktop application, update machine.config of the appropriate .NET version folder (there are pitfalls like Framework and Framework64 :) )
- If it is a web application hosted in IIS, update the web.config located at the same location where machine.config is generally found. I learned it the hard way.
Let us hope, no one runs into proxy issues again. Ever!!
No comments:
Post a Comment