473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

"401 unauthorized access" error

ag
Hi guys.. need your help.

We have abc.asp page on the source server which calls a .net component on that server. The component is in MTS running under say "domain2\id1" identity. The component uses HttpWebRequest to call xyz.asp on the target server. Both servers are under the same domain say domain1 and there is a trust between domain1 and domain2.

The problem is the target server is returning 401 unauthorized access when calling xyz.asp from the component which is on the source server. It is running fine when anonymous authentication is set on the target server vdir but throwing the above error with integrated win auth which is what we want it to run under. The source server vdir is also set to integrated win auth.

Here is the C# component code for your ref:
------------------------------------------------
//Create the Web request object. Use the Create method instead of the constructor
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(strURL);

//Set the keep alive property to false to prevent caching of credentials
myHttpWebRequest.KeepAlive = false;

//Set the method to POST
myHttpWebRequest.Method = "POST";

//Set the proxy settings
string[] arrByPassLists = {cstrProxyByPassList};
WebProxy myWebProxy = new WebProxy(cstrProxySrvrUri, true, arrByPassLists);
myHttpWebRequest.Proxy = myWebProxy;

//Set the timeout value (in milliseconds)
myHttpWebRequest.Timeout = cintTimeOutVal;

//Set the content type
myHttpWebRequest.ContentType = "application/x-zip-compressed"; //TODO: Set the content type to binary

//Write all the zip file data to the request string

//Open the zip file for reading
FileStream myFileStream = File.OpenRead(strZipPath);

//Open the request stream for writing
Stream myRequestStream = myHttpWebRequest.GetRequestStream();

//Loop through to write the zip file data
byte[] myBuffer = new byte[cintBufferLen];
int intBytesRead;
long lngTotalSize = 0;
intBytesRead = myFileStream.Read(myBuffer, 0, cintBufferLen);
while(intBytesRead > 0)
{
lngTotalSize+= intBytesRead;
myRequestStream.Write(myBuffer, 0, intBytesRead);
intBytesRead = myFileStream.Read(myBuffer, 0, cintBufferLen);
};

//Close the streams
myFileStream.Close();
myRequestStream.Close();

//End of writing the zip file data to the stream

//Contact the server and get the response from it
WebResponse myWebResponse;
string strResponse;

//Get the response
myWebResponse = myHttpWebRequest.GetResponse() //Getting 401 error here in response
---------------------------------------

Let me know if you need any more info...

Thanks much.
AG

Posted via DevelopmentNow Group
www.developmentnow.com/
www.developmentnow.com
Nov 22 '05 #1
1 3411
I don't see where you're specifying any credentials associated with your HTTP
request. Try setting the HttpWebRequest.Credentials =
System.Net.CredentialCache.DefaultCredentials before making the call.

Hope this helps.

"ag" wrote:
Hi guys.. need your help.

We have abc.asp page on the source server which calls a .net component on that server. The component is in MTS running under say "domain2\id1" identity. The component uses HttpWebRequest to call xyz.asp on the target server. Both servers are under the same domain say domain1 and there is a trust between domain1 and domain2.

The problem is the target server is returning 401 unauthorized access when calling xyz.asp from the component which is on the source server. It is running fine when anonymous authentication is set on the target server vdir but throwing the above error with integrated win auth which is what we want it to run under. The source server vdir is also set to integrated win auth.

Here is the C# component code for your ref:
------------------------------------------------
//Create the Web request object. Use the Create method instead of the constructor
HttpWebRequest myHttpWebRequest = (HttpWebRequest)HttpWebRequest.Create(strURL);

//Set the keep alive property to false to prevent caching of credentials
myHttpWebRequest.KeepAlive = false;

//Set the method to POST
myHttpWebRequest.Method = "POST";

//Set the proxy settings
string[] arrByPassLists = {cstrProxyByPassList};
WebProxy myWebProxy = new WebProxy(cstrProxySrvrUri, true, arrByPassLists);
myHttpWebRequest.Proxy = myWebProxy;

//Set the timeout value (in milliseconds)
myHttpWebRequest.Timeout = cintTimeOutVal;

//Set the content type
myHttpWebRequest.ContentType = "application/x-zip-compressed"; //TODO: Set the content type to binary

//Write all the zip file data to the request string

//Open the zip file for reading
FileStream myFileStream = File.OpenRead(strZipPath);

//Open the request stream for writing
Stream myRequestStream = myHttpWebRequest.GetRequestStream();

//Loop through to write the zip file data
byte[] myBuffer = new byte[cintBufferLen];
int intBytesRead;
long lngTotalSize = 0;
intBytesRead = myFileStream.Read(myBuffer, 0, cintBufferLen);
while(intBytesRead > 0)
{
lngTotalSize+= intBytesRead;
myRequestStream.Write(myBuffer, 0, intBytesRead);
intBytesRead = myFileStream.Read(myBuffer, 0, cintBufferLen);
};

//Close the streams
myFileStream.Close();
myRequestStream.Close();

//End of writing the zip file data to the stream

//Contact the server and get the response from it
WebResponse myWebResponse;
string strResponse;

//Get the response
myWebResponse = myHttpWebRequest.GetResponse() //Getting 401 error here in response
---------------------------------------

Let me know if you need any more info...

Thanks much.
AG.

Posted via DevelopmentNow Groups
www.developmentnow.com/g
www.developmentnow.com

Nov 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: CLEAR-RCIC | last post by:
I'm trying to use the Webclient class to "POST" to a web site. The website is using basic authentication. Im getting a "(401) Unauthorized" error. Here is my basic code: dim myWebClient as...
1
by: ag | last post by:
Hi guys.. need your help. We have abc.asp page on the source server which calls a .net component on that server. The component is in MTS running under say "domain2\id1" identity. The component...
1
by: CLEAR-RCIC | last post by:
I'm trying to use the Webclient class to "POST" to a web site. The website is using basic authentication. Im getting a "(401) Unauthorized" error. Here is my basic code: dim myWebClient as...
0
by: =?Utf-8?B?R2VvcmdlIFNodWk=?= | last post by:
I have a folder structure such like this. A ---A1 -----a1.aspx ---A2 A1 and A2 are the subfolder of A. And under the A1 folder, it contains one aspx file named a1.aspx. I set the IIS virtual...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.