Re: StreamWrite / Problem?
From: Leon (vnality_at_msn.com)
Date: 12/04/04
- Next message: Leon: "Re: StreamWrite / Problem?"
- Previous message: Johann MacDonagh: "Re: Code behind problem"
- In reply to: Johann MacDonagh: "Re: StreamWrite / Problem?"
- Next in thread: Leon: "Re: StreamWrite / Problem?"
- Reply: Leon: "Re: StreamWrite / Problem?"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 4 Dec 2004 07:06:09 -0600
Now I'm getting the following error, what should I do? I once read it is a
bad idea to give ASP.NET WRITE access to the C: drive.
Server Error in '/MySite' Application.
--------------------------------------------------------------------------------
Access to the path "c:\inetpub\wwwroot\MySite\ErrorLog.txt" is denied.
Exception Details: System.UnauthorizedAccessException: Access to the path
"c:\inetpub\wwwroot\MySite\ErrorLog.txt" is denied.
ASP.NET is not authorized to access the requested resource. Consider
granting access rights to the resource to the ASP.NET request identity.
ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or
Network Service on IIS 6) that is used if the application is not
impersonating. If the application is impersonating via <identity
impersonate="true"/>, the identity will be the anonymous user (typically
IUSR_MACHINENAME) or the authenticated request user.
To grant ASP.NET write access to a file, right-click the file in Explorer,
choose "Properties" and select the Security tab. Click "Add" to add the
appropriate user or group. Highlight the ASP.NET account, and check the
boxes for the desired access.
"Johann MacDonagh" <JohannMacDonagh.RemoveThis@msn.com> wrote in message
news:e62B61f2EHA.524@TK2MSFTNGP09.phx.gbl...
> Server.MapPath("") should return C:\Inetpub\wwwroot\MySite Therefore, you
> should modify the Server.MapPath line to:
>
> Dim filePath As String = context.Server.MapPath( "ErrorLog.txt")
>
> That should create the filename C:\Inetpub\wwwroot\MySite\ErrorLog.txt
>
> Just a few things. HttpContext.Current.Server and Page.Server (or just
> Server if you are coding in the code behind) are the same object. You can
> save yourself a few lines by removing the code to get the Current
> HttpContext and using it's Server property.
>
> Also, you should have the StreamWriter's close method in the Finally
> portion of your Try / Catch. There's been many times when I've forgotten
> to close a connection to a file / database when I hit an exception, and
> the database (especially if you're using Access) doesn't allow connections
> for a while.
>
> Hope I could help!
>
> Happy coding,
> Johann MacDonagh
> "Leon" <vnality@msn.com> wrote in message
> news:OnAvHXd2EHA.1204@TK2MSFTNGP10.phx.gbl...
>>I wrote an custom error handler that works, but why the ErrorLog.txt file
>>is being created/written in the root web instead of the folder within my
>>web application?
>> Root web = C:\Inetpub\wwwroot -&- Web Application Folder =
>> C:\Inetpub\wwwroot\MySite
>> See code:
>> Public Shared Sub LogError(ByVal message As String)
>> ' Get the current HTTPContext
>> Dim context As HttpContext = HttpContext.Current
>> ' Get location of ErrorLogFile from Web.config file
>> Dim filePath As String = context.Server.MapPath( "../../ErrorLog.txt")
>> ' Write message to error file
>>
>> Try
>> Dim sw As New System.IO.StreamWriter(filePath, True)
>> sw.WriteLine(message)
>> sw.WriteLine()
>> sw.Close()
>>
>> Catch
>> ' If error writing to file, simply continue
>> End Try
>>
>> End Sub
>> End Class
>> End Namespace
>> and if I try to hard code write the error to my ErrorLog text file it in
>> my web application (such as "MySite/ErrorLog.txt") nothing gets written?
>>
>
>
- Next message: Leon: "Re: StreamWrite / Problem?"
- Previous message: Johann MacDonagh: "Re: Code behind problem"
- In reply to: Johann MacDonagh: "Re: StreamWrite / Problem?"
- Next in thread: Leon: "Re: StreamWrite / Problem?"
- Reply: Leon: "Re: StreamWrite / Problem?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|