Quantcast
Channel: .NET Framework Class Libraries forum
Viewing all articles
Browse latest Browse all 8156

Unable to create file from Application_Start() event.

$
0
0

Hi,

(Sorry if this is in the wrong forum, but I couldn't find a better one.)

I have some code which attempts to create and write to a log file in a subdirectory of my website (shown below). If I put the first call to this code in the Page_Load() event of Default.aspx, it works fine every time. If, however, I make the first call to this code inside the Global.asax Application_Start() event, I get an access denied exception from .NET, even though the path displayed in the exception message is correct and is a subdirectory of my site root.

Has anyone encountered anything like this? It is as if the code running from Application_Start() has a more limited set of permissions than code running later.

Kind wishes ~ Patrick

string s = string.Format( "{0}logs\\Log.txt", HttpRuntime.AppDomainAppPath );
using( StreamWriter writer = new StreamWriter( s, true ) )
{
	string logEntry = DateTime.Now.ToString() + ": " + formattedMessage;
	writer.WriteLine( logEntry );
	writer.Flush();
}



Viewing all articles
Browse latest Browse all 8156

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>