Hi DWrek,
Thanks for your response. I did some further research on this and here are
the findings:
When you are using <proxy usesystemdefault="true"/> (which is the default
in
machine.config file), then it will try to access the IE settings. These
settings
are stored in the HKCU hive of the registry. This hive is per user and is
loaded
only when somebody is logged on to the machine. Setting this to default
makes sense
only when you are writing client interactive applications (like Windows
Forms
application). In which case the settings will be same as IE settings for
that user
(the user would have logged onto the machine where the code is run). There
is
another caveat to this : This will not apply for "Use automatic
configuration
script" setting as documented in the <proxy> section in the config file.
You need
to explicitly specify the proxy server in IE options.
In your scenrio you are doing this from a web application which is non
interactive
user (nobody logged on).
For web applications, it seems that we should always
use the following workarounds:
1)Use the Proxy class in the code and specify it in Webrequest class as
follows.
This will result in not taking the settings from config files.
public string MakeQuerywithproxy()
{
WebProxy proxyObject;
proxyObject = new WebProxy("<replace with proxy in SF>", 80);
WebRequest request = WebRequest.Create("<replace with some external web
address>");
request.Proxy = proxyObject;
WebResponse response = request.GetResponse();
TextReader reader = new StreamReader(response.GetResponseStream());
String content = reader.ReadToEnd();
reader.Close();
return content;
}
2)Specify proxy that you want a web application to use in the web.config
file:
<defaultProxy>
<proxy
usesystemdefault = "false"
proxyaddress = "http://proxyserver:80"
bypassonlocal = "true"
/>
<defaultProxy/>
This should override the machine.config file contents.
However, as for your senario, since you're calling the assembly in classic
ASP page which didn't have a web.config (if use app.config , we may need to
provide a config for the DllHost.exe such as DllHost.exe.config which may
have no difference from changing machine.config) and you also mentioned
that the exception occur just at you creating the WebRequest( have no
chance to set the Proxy ,yes?). I feel abit strange at this, I've done a
simple test on my side expose a .net class as below:
===============================
[ClassInterface(ClassInterfaceType.AutoDual)]
public class WebRequestUtil
{
public string GetWebPageContent(string url)
{
string html = string.Empty;
WebRequest wq = HttpWebRequest.Create(url);
wq.Proxy = new WebProxy(wq.Proxy.GetProxy(new Uri(url)));
WebResponse wp = wq.GetResponse();
StreamReader sr = new
StreamReader(wp.GetResponseStream(),System.Text.En coding.UTF8);
html = sr.ReadToEnd();
return html;
}
}
==================================
as COM interop and call it in classic asp. I configure the asp app's
vritual dir as allow anonymous and use the IUser_Machine account (only in
the Users group). But the code works well. So I'm wondering whether there
is any enviromental specific issue? Would you have a test on some other
machines to see whether they can make httpwebrequest call correctly( just
request a certain external site like google.com or ...)?
Please feel free to let me know if there is any new findings or problems.
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)