Another mappath error

  • Thread starter Thread starter Bill
  • Start date Start date
B

Bill

In the DownLoad method below, the path I am passing to the
streamwriter object is triggering the following exception but I dont
know why.

Access to the path 'E:\clnts\www.myapp.com\downloads.log' is denied.

This happens only on the host web server. No error on a local machine.
The streamwriter successfully writes to the downloads.log file, but if
I remove the try/catch block then I get an unhandled excpeption and
the downloads.log file is not written to. So my page works, and I can
simply remove the redirect to the errorpage and forget about it, but I
sure would like to know what is causing the error. Seems to be some
sort of permission violation, but why does it go ahead and write to
the file if that is the case?


protected void DownLoad(object sender, EventArgs e)
{
Response.Redirect("~/Downloads/xmlmaxbeta.zip", false);
//executes before dialog is shown
try
{
using (System.IO.StreamWriter sw = new
System.IO.StreamWriter(Server.MapPath("~/") + "downloads.log", true))
{
//write comma delimited string so file may be loaded
into excel and sorted
sw.WriteLine(DateTime.Today.ToShortDateString() + ","
+ Convert.ToString(Session["PwdHash"]));
sw.Close();
}
}
catch (System.IO.IOException ioex)
{
Session["ErrorMessage"] = ioex.Message + " IO exception";
Response.Redirect("~/ErrorPage.aspx");
}
catch (Exception ex)
{
Session["ErrorMessage"] = ex.Message + " general
exception";
Response.Redirect("~/ErrorPage.aspx");
}
}
 
I would guess some form of trust issue. Not sure why it would allow the
logging with that in place. Most likely you have everything working off the
ASP.NET worker process user, and the ISP has it restricted.

Generally, with logging, I use some form of logging block. MS has one in the
EntLib, but there are other open source implementations that do not require
carrying along all the other baggage. The name of the one we have usd in the
past escapes me at this moment. The benefit of these libaries is they
generally have more instrumentation built in and have been tested on a wider
variety of platforms.

--
Gregory A. Beamer
MVP: MCP: +I, SE, SD, DBA

Blog:
http://feeds.feedburner.com/GregoryBeamer

********************************************
| Think Outside the Box! |
********************************************
 
Back
Top