Re: StreamWrite / Problem?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Leon (vnality_at_msn.com)
Date: 12/04/04


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?
>>
>
>



Relevant Pages

  • Re: Database index is corruption . I dont know how to explain to my client]
    ... IF this data resides on the server - then use a server based anti-virus ... > I told my client the database index is corruption due to some client PC ... > effected by client computer even the client computer was hang or had ... > sending a request to server to ask for data modification. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Timeout problems
    ... I am assuming that the time out is a scripting timeout on your browser. ... we have a request to the SQL Server ... database to run a stored procedure to return the data. ...
    (microsoft.public.dotnet.general)
  • Database index is corruption . I dont know how to explain to my client]
    ... I told my client the database index is corruption due to some client PC ... The data of the shipping program is stored in server and client computer is ... sending a request to server to ask for data modification. ...
    (microsoft.public.fox.programmer.exchange)
  • Re: The best way to wait for something to happen
    ... You can use UDP to communicate between PCs, ... REQUEST a request for information from another user ... The first two types I will probably want to store in a database for history. ... I like the server idea, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: eliminates the page_load
    ... request to the server. ... If you really want to avoid Page_Load you could ... and also doing update to database. ...
    (microsoft.public.dotnet.framework.aspnet)