HTTPWebRequest.request.GetResponse fails: remote server returned error: (401) unauthorized.
HTTPWebRequest.request.GetResponse fails: remote server returned error: (401) unauthorized.
am 20.03.2007 19:14:26 von Grant_Sutty
I have an asp.net web application which posts a request to another
asp.net web application. I am coding in C# using Visual studio 2003,
with .Net Framework 1.1 on a Wiondows 2003 server (running IIS 6.0.).
In order to have all code running as managed code, I changed existing
code which uses MSXML ServerXMLHTTPClass to post requests to code
using the .Net HTTPWebRequest class. When migrating the application to
the Test web server, IIS appears to prevent access (=no record of the
request in the Windows\System32\Logfiles\W3SVC1 files). I am using
impersonation in the web.config file of the client and 'server' web
applications. The Application needs to be configured in IIS to
'Windows Authentication' only. The impersonated account is a member of
IIS_WPG group an has NTFS permissions to the Applications physical
folder. Even if I open up security (allow everyone). There is no web
proxy issue. Both client and Server applications are at this point
both on the same Test server with the same specs as the development
machine (above).
THE ONLY WAY IT FUNCTIONS IS IF IIS FOR THE APPLICATION ON THE SERVER
HAS 'ENABLE ANONYMOUS' TICKED.
I see a lot of posts on the internet highlighting this problem without
any difinitive answer. Surely, Microsoft wishes the Managed classes to
be used. Why then does there appear to be such a hassle for coders to
use the class to achieve the same result as the MSXML classes?
The code below is what I am using to make the call. Tracing shows that
the call fails when the request is made (GetResponse()).
HttpWebRequest request=null;
Uri uri = new Uri(requestTargetAndQuery);
request = (HttpWebRequest) WebRequest.Create(uri);
request.Method = "GET";
request.Credentials = new NetworkCredential(this.m_User,
this.m_Password);
string result=string.Empty;
using (HttpWebResponse response = (HttpWebResponse)
request.GetResponse())
{
request response.",traceSwitch);
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader readStream = new StreamReader
(responseStream, Encoding.UTF8))
{ result = readStream.ReadToEnd();
}
}
}
Hopefully someone can point me in the right direction (or let me know
if the Framework class does not have the capability to achieve what I
am trying)
Thanks Grant_S
Re: HTTPWebRequest.request.GetResponse fails: remote server returned error: (401) unauthorized.
am 23.03.2007 03:47:41 von Steve Schofield
Hi Grant,
Have you tried using BASIC Authentication and / or Windows Integrated
Authentication to see if this works?
--
Steve Schofield
Windows Server MVP - IIS
ASPInsider Member - MCP
http://www.orcsweb.com/
Managed Complex Hosting
#1 in Service and Support
"Grant_Sutty" wrote in message
news:1174414466.211293.254830@e1g2000hsg.googlegroups.com...
>I have an asp.net web application which posts a request to another
> asp.net web application. I am coding in C# using Visual studio 2003,
> with .Net Framework 1.1 on a Wiondows 2003 server (running IIS 6.0.).
> In order to have all code running as managed code, I changed existing
> code which uses MSXML ServerXMLHTTPClass to post requests to code
> using the .Net HTTPWebRequest class. When migrating the application to
> the Test web server, IIS appears to prevent access (=no record of the
> request in the Windows\System32\Logfiles\W3SVC1 files). I am using
> impersonation in the web.config file of the client and 'server' web
> applications. The Application needs to be configured in IIS to
> 'Windows Authentication' only. The impersonated account is a member of
> IIS_WPG group an has NTFS permissions to the Applications physical
> folder. Even if I open up security (allow everyone). There is no web
> proxy issue. Both client and Server applications are at this point
> both on the same Test server with the same specs as the development
> machine (above).
>
> THE ONLY WAY IT FUNCTIONS IS IF IIS FOR THE APPLICATION ON THE SERVER
> HAS 'ENABLE ANONYMOUS' TICKED.
>
> I see a lot of posts on the internet highlighting this problem without
> any difinitive answer. Surely, Microsoft wishes the Managed classes to
> be used. Why then does there appear to be such a hassle for coders to
> use the class to achieve the same result as the MSXML classes?
>
> The code below is what I am using to make the call. Tracing shows that
> the call fails when the request is made (GetResponse()).
>
> HttpWebRequest request=null;
> Uri uri = new Uri(requestTargetAndQuery);
> request = (HttpWebRequest) WebRequest.Create(uri);
> request.Method = "GET";
> request.Credentials = new NetworkCredential(this.m_User,
> this.m_Password);
> string result=string.Empty;
> using (HttpWebResponse response = (HttpWebResponse)
> request.GetResponse())
> {
> request response.",traceSwitch);
> using (Stream responseStream = response.GetResponseStream())
> {
> using (StreamReader readStream = new StreamReader
> (responseStream, Encoding.UTF8))
> { result = readStream.ReadToEnd();
> }
> }
> }
>
> Hopefully someone can point me in the right direction (or let me know
> if the Framework class does not have the capability to achieve what I
> am trying)
>
> Thanks Grant_S
>
Re: HTTPWebRequest.request.GetResponse fails: remote server returned error: (401) unauthorized.
am 23.03.2007 09:05:20 von Grant_Sutty
On Mar 23, 2:47 am, "Steve Schofield" wrote:
> Hi Grant,
>
> Have you tried using BASIC Authentication and / or Windows Integrated
> Authentication to see if this works?
> --
>
> Steve Schofield
> WindowsServerMVP - IIS
> ASPInsider Member - MCP
>
> http://www.orcsweb.com/
> Managed Complex Hosting
> #1 in Service and Support
>
> "Grant_Sutty" wrote in message
>
> news:1174414466.211293.254830@e1g2000hsg.googlegroups.com...
>
>
>
> >I have an asp.net web application which posts a request to another
> > asp.net web application. I am coding in C# using Visual studio 2003,
> > with .Net Framework 1.1 on a Wiondows 2003server(running IIS 6.0.).
> > In order to have all code running as managed code, I changed existing
> > code which uses MSXML ServerXMLHTTPClass to post requests to code
> > using the .Net HTTPWebRequest class. When migrating the application to
> > the Test webserver, IIS appears to prevent access (=no record of the
> > request in the Windows\System32\Logfiles\W3SVC1 files). I am using
> > impersonation in the web.config file of the client and 'server' web
> > applications. The Application needs to be configured in IIS to
> > 'Windows Authentication' only. The impersonated account is a member of
> > IIS_WPG group an has NTFS permissions to the Applications physical
> > folder. Even if I open up security (allow everyone). There is no web
> > proxy issue. Both client andServerapplications are at this point
> > both on the same Testserverwith the same specs as the development
> > machine (above).
>
> > THE ONLY WAY IT FUNCTIONS IS IF IIS FOR THE APPLICATION ON THESERVER
> > HAS 'ENABLE ANONYMOUS' TICKED.
>
> > I see a lot of posts on the internet highlighting this problem without
> > any difinitive answer. Surely, Microsoft wishes the Managed classes to
> > be used. Why then does there appear to be such a hassle for coders to
> > use the class to achieve the same result as the MSXML classes?
>
> > The code below is what I am using to make the call. Tracing shows that
> > the callfailswhen the request is made (GetResponse()).
>
> > HttpWebRequest request=null;
> > Uri uri = new Uri(requestTargetAndQuery);
> > request = (HttpWebRequest) WebRequest.Create(uri);
> > request.Method = "GET";
> > request.Credentials = new NetworkCredential(this.m_User,
> > this.m_Password);
> > string result=string.Empty;
> > using (HttpWebResponse response = (HttpWebResponse)
> > request.GetResponse())
> > {
> > request response.",traceSwitch);
> > using (Stream responseStream = response.GetResponseStream())
> > {
> > using (StreamReader readStream = new StreamReader
> > (responseStream, Encoding.UTF8))
> > { result = readStream.ReadToEnd();
> > }
> > }
> > }
>
> > Hopefully someone can point me in the right direction (or let me know
> > if the Framework class does not have the capability to achieve what I
> > am trying)
>
> > Thanks Grant_S- Hide quoted text -
>
> - Show quoted text -
Hi Steve
Thanks for your input. I finally got there yesterday. I am now able to
use IIS Windows Integrated only, I have 'allow' and 'deny' tags set
in the application web.config file; I am using the
tag in the web.config file. The thing that I had incorrect was that I
needed to use the 'domain' property when setting the network
credentials.
Cheers
Grant
Re: HTTPWebRequest.request.GetResponse fails: remote server returned error: (401) unauthorized.
am 23.03.2007 14:59:30 von Steve Schofield
That is great information. Thanks for posting the resolution.
--
Thank you,
Steve Schofield
Windows Server MVP - IIS
ASPInsider Member - MCP
http://www.orcsweb.com/
Managed Complex Hosting
#1 in Service and Support
"Grant_Sutty" wrote in message
news:1174637120.792413.10060@b75g2000hsg.googlegroups.com...
> On Mar 23, 2:47 am, "Steve Schofield" wrote:
>> Hi Grant,
>>
>> Have you tried using BASIC Authentication and / or Windows Integrated
>> Authentication to see if this works?
>> --
>>
>> Steve Schofield
>> WindowsServerMVP - IIS
>> ASPInsider Member - MCP
>>
>> http://www.orcsweb.com/
>> Managed Complex Hosting
>> #1 in Service and Support
>>
>> "Grant_Sutty" wrote in message
>>
>> news:1174414466.211293.254830@e1g2000hsg.googlegroups.com...
>>
>>
>>
>> >I have an asp.net web application which posts a request to another
>> > asp.net web application. I am coding in C# using Visual studio 2003,
>> > with .Net Framework 1.1 on a Wiondows 2003server(running IIS 6.0.).
>> > In order to have all code running as managed code, I changed existing
>> > code which uses MSXML ServerXMLHTTPClass to post requests to code
>> > using the .Net HTTPWebRequest class. When migrating the application to
>> > the Test webserver, IIS appears to prevent access (=no record of the
>> > request in the Windows\System32\Logfiles\W3SVC1 files). I am using
>> > impersonation in the web.config file of the client and 'server' web
>> > applications. The Application needs to be configured in IIS to
>> > 'Windows Authentication' only. The impersonated account is a member of
>> > IIS_WPG group an has NTFS permissions to the Applications physical
>> > folder. Even if I open up security (allow everyone). There is no web
>> > proxy issue. Both client andServerapplications are at this point
>> > both on the same Testserverwith the same specs as the development
>> > machine (above).
>>
>> > THE ONLY WAY IT FUNCTIONS IS IF IIS FOR THE APPLICATION ON THESERVER
>> > HAS 'ENABLE ANONYMOUS' TICKED.
>>
>> > I see a lot of posts on the internet highlighting this problem without
>> > any difinitive answer. Surely, Microsoft wishes the Managed classes to
>> > be used. Why then does there appear to be such a hassle for coders to
>> > use the class to achieve the same result as the MSXML classes?
>>
>> > The code below is what I am using to make the call. Tracing shows that
>> > the callfailswhen the request is made (GetResponse()).
>>
>> > HttpWebRequest request=null;
>> > Uri uri = new Uri(requestTargetAndQuery);
>> > request = (HttpWebRequest) WebRequest.Create(uri);
>> > request.Method = "GET";
>> > request.Credentials = new NetworkCredential(this.m_User,
>> > this.m_Password);
>> > string result=string.Empty;
>> > using (HttpWebResponse response = (HttpWebResponse)
>> > request.GetResponse())
>> > {
>> > request response.",traceSwitch);
>> > using (Stream responseStream = response.GetResponseStream())
>> > {
>> > using (StreamReader readStream = new StreamReader
>> > (responseStream, Encoding.UTF8))
>> > { result = readStream.ReadToEnd();
>> > }
>> > }
>> > }
>>
>> > Hopefully someone can point me in the right direction (or let me know
>> > if the Framework class does not have the capability to achieve what I
>> > am trying)
>>
>> > Thanks Grant_S- Hide quoted text -
>>
>> - Show quoted text -
>
> Hi Steve
>
> Thanks for your input. I finally got there yesterday. I am now able to
> use IIS Windows Integrated only, I have 'allow' and 'deny' tags set
> in the application web.config file; I am using the
> tag in the web.config file. The thing that I had incorrect was that I
> needed to use the 'domain' property when setting the network
> credentials.
>
> Cheers
>
> Grant
>
remote server returned error: (401) unauthorized
am 06.12.2007 07:22:55 von unknown
can you please describe your solution in detail and if possible can you please paste your code
EggHeadCafe - .NET Developer Portal of Choice
http://www.eggheadcafe.com
Re: remote server returned error: (401) unauthorized
am 06.12.2007 09:32:43 von Anthony Jones
wrote in message
news:200712612255dishant.buch@eclipsys.com...
> can you please describe your solution in detail and if possible can you
please paste your code
>
Make sure the user accessing the resource is authorised to read it.
If you want a detailed answer ask a detailed question.
--
Anthony Jones - MVP ASP/ASP.NET