Another mappath error

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");
}
}
 
G

Gregory A. Beamer

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top