473,387 Members | 1,528 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,387 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 3414
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.