I have been trying to enable write permission for NETWORK SERVICE account to be able to write to a file. My PC has Windows XP Home edition running on it.
I have followed steps detailed in Appendix B of ASP.NET 2.0 Beginner, namely 'Windows XP Home Edition Users Only' and also in chapter 16 'Enable App Data Permissions' and even when the file and the folder it is in have read/write/execute permissions enabled for both NETWORK SERVICE and ASPNET accounts, when I upload the folder and file and run the website on my host domain I get an error that there is a security issue, and when I enable CustomErrors in the Web.Config file then I get HTTP Error 404 - File or Directory not found.
Has anyone had similar problems with these accounts and found a solution or simply can see what I'm doing wrong.
If it helps, the file contains a counter for a simple hit counter, this is updated then read whenever the page is loaded. (the code is attached below).
Code:
Imports System.IO
Partial Class TestPage
Inherits System.Web.UI.Page
Dim ct As String
Dim CounterPage As String = Server.MapPath("~/counters/HitCounter.txt")
Sub ReadFile()
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(CounterPage)
ct = objStreamReader.ReadToEnd()
ct = CLng(ct)
ct = ct + 1
objStreamReader.Close()
End Sub
Sub WriteFile()
Dim objFileWriter As StreamWriter
objFileWriter = File.CreateText(CounterPage)
objFileWriter.Write(ct.ToString)
objFileWriter.Close()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
ReadFile()
WriteFile()
Label1.Text = ct
End Sub
End Class