ASP.Net ERROR: The remote server returned an error: (401) Unauthorized. RESOLVED


I struggled with this error(The remote server returned an error: (401) Unauthorized.) for 2 weeks.

Here is my setup:
IIS with integrated Authentication.
There is no user login thus the user name and password isn’t getting stored.

Finally after grabbing bit and pieces of the Internet my error has been resolved. Here is my solution:

String path = templateData.getField(TemplateData.FieldName.LOGO);
System.Net.WebRequest objRequest = System.Net.WebRequest.Create(path);
objRequest.UseDefaultCredentials = true;
objRequest.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;
System.Net.WebResponse objResponse = objRequest.GetResponse();
System.IO.Stream  strm = objResponse.GetResponseStream();
System.IO.StreamReader rdr = new System.IO.StreamReader(strm);
Image logoImage = Image.GetInstance(strm);
objResponse.Close();

Hope this helps someone

Advertisements

2 thoughts on “ASP.Net ERROR: The remote server returned an error: (401) Unauthorized. RESOLVED

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s