I have an ASP.NET application where I'm trying to output the previously-visited local aspx page to html (its a report and I want to store a static html copy of it as an archive). I store the uri of the local page with:
Session["SummaryURI"] = Request.Url.AbsoluteUri;
and then in the next page I retrieve it with:
string url = Session["SummaryURI"].ToString();
url = url.Replace("static=false", "static=true");
//MessageLabel.Text = url;
//CREATE THE NEW FILE
WebRequest req = WebRequest.Create(url);
WebResponse res = req.GetResponse();
The part req.GetResponse()
is where I'm getting my error (401 Unauthorized
).
Do I need to configure something in IIS to allow this?
Do I need to edit file permissions or something?
Thanks for your help
By the way this works fine on my local IIS but not on my test server.
If you cannot enable Anonymous Authentication, try adding this to your WebRequest:
req.UseDefaultCredentials = true;
req.PreAuthenticate = true;
req.Credentials = CredentialCache.DefaultCredentials;
I think the issue is because authentication on the test IIS server. Two options:
1) Enable "Anonymous Authentication" for the Site on test IIS Server.
2) (Recommended) Before making the request to test server use the code template below with right username/password/domain information that can be authenticated against the test server.
System.Net.NetworkCredential netCredential =
new System.Net.NetworkCredential("<USER_NAME>", "<PASSWORD>", "<DOMAIN>");
req.Credentials = netCredential;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With