HTTPWebResponse: Winform = Pass; ASP DLL = Fail

G

Guest

Hello,

I am having an issue with an object (deployed as VB.Net dll w/ Interop)
instanciated from an ASP page. The object is created just fine but fails when
attempting to make an HTTPWebRequest to another companies HTTP server. This
same object works just fine from a Windows Form. The error I keep getting
from the ASP hosted version of the object is as follows:

"Exception in configuration section
handler(c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config
line 74)"

The "line 74" area of my machine.config deals with the proxy configuration.

The confusing part, for me, is that my internet connection does not make
use of a proxy server. In Internet Explorer I do not have any proxy settings
enabled. Also, why would I be able to reach an outside server under a
WinForms application but not from an ASP page using the same dll? Thank you
for any ideas or suggestions.

- DWek
 
B

bruce barker

a winform app runs under your user profile, where you have setup the intenet
connection settings with IE. an asp.net page runs under a service account
with no profile, so no internet settings exist, so the ones in machine
config are used. these need to be setup correctly for your enviroment.

-- bruce (sqlwork.com)


| Hello,
|
| I am having an issue with an object (deployed as VB.Net dll w/ Interop)
| instanciated from an ASP page. The object is created just fine but fails
when
| attempting to make an HTTPWebRequest to another companies HTTP server.
This
| same object works just fine from a Windows Form. The error I keep getting
| from the ASP hosted version of the object is as follows:
|
| "Exception in configuration section
| handler(c:\windows\microsoft.net\framework\v1.1.4322\Config\machine.config
| line 74)"
|
| The "line 74" area of my machine.config deals with the proxy
configuration.
|
| The confusing part, for me, is that my internet connection does not make
| use of a proxy server. In Internet Explorer I do not have any proxy
settings
| enabled. Also, why would I be able to reach an outside server under a
| WinForms application but not from an ASP page using the same dll? Thank
you
| for any ideas or suggestions.
|
| - DWek
|
 
S

Steven Cheng[MSFT]

Hi DWrek,

I think Bruce's suggestion is reasonable. Since the ASP(OR ASP.NET) are
running under the the certaihn service's service account which is different
from the winform app(use the logon user account). Have you also tried the
same code in an asp.net web application? I think the problem is also likely
to occur. You can have a try and also check to see whether there is any
internal or external proxy we need to specify.
If there is any new findings, please feel free to post here.
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.)
 
G

Guest

Thank you both for your suggestions. I believe you are right on target. I was
able to resolve the issue by editing the machine.config file on my system.

After taking a closer look at the exception I was getting I found there to
be an "Inner Exception" within the original exception. Looking at this inner
exception I found there was an error trying to access the registry. What I
think was happening was this:

1) In the machine.config the key <proxy usesystemdefault="true"> was set to
true.
2) Because of this the ASP.NET page was trying to access the registry to
determine what my default proxy settings were (derived from Internet
Explorer).
3) It was here that the exception was thrown because the "ASPNET" account
did not have permissions to access the registry and hence, the exception I
was seeing.

So I solved the problem by setting the attribute of the <proxy> key to
"usesystemdefault=false". Now though this solves the problem it does make it
necessary to alter the machine.config file on every web server that I deploy
this solution on. I would like to avoid this so I am looking for a way to
bypass the proxy directly from the .NET dll. Any suggestions?
 
S

Steven Cheng[MSFT]

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.Encoding.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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top