incorrect Error 404 (file not found) from WebRequest on IIS 6
Posted on 2007-03-23
I originally asked this in the ASP zone, but I'm begining to think it's a server configuration issue.
I'm attempting to call an ASP.NET 2.0 aspx file using WebRequest / WebResponse. The file builds a dynamic style sheet from a given XML file, and I want to be able to save the resulting CSS file as a file. When I test it on my localhost machine, it works correctly. Once it's live, it gives an incorrect error 404 (page not found). I have it sending the URI back in the catch routine, and when I put it into the address bar, it works correctly. I also have a page that links to the aspx file the same as it would a CSS file. Again, local it works, live it doesn't. Finally, I tested the WebRequest with a hard coded Uri pointing to the file on the server. Locally it worked (the reference page running locally, trying to connect to the file on the server), live it didn't.
We're running on Windows 2003. I have found various possibilities, including having WebDav disabled (it isn't), having IIS Lockdown utility run (it isn't), problems with UrlScan utility configuration (not used), and MIME settings. The last is a possibility - since we are requesting an ASPX file, but returning a content type of "text/css".
I don't think it's code related, but it's possible, so here's the code I'm using.
string dir = Server.MapPath("~") + "\\css\\" + (string)ViewState["merchname"];
CSSInfo csssheet = new CSSInfo(StyleList, imagelist, dir);
csssheet.CSS_SaveFile(); //creates the XML file from the set variables
UriBuilder dcssb = new UriBuilder(this.Request.Url.AbsoluteUri.Replace("DonationConfiguration.aspx","donationcss1.aspx"));
dcssb.Query = "MerchantID=" + (string)ViewState["merchname"];
Uri dcss = dcssb.Uri;
WebRequest webreq = WebRequest.Create(dcss);
WebResponse webrsp = webreq.GetResponse();
Stream stream = webrsp.GetResponseStream();
StreamReader strrdr = new StreamReader(stream);
StreamWriter strwrt = new StreamWriter(dir + "\\donation.css");