I am trying to read some html files using FileStream, StreamReader located in a sub-folder [Templates] within my application (virtual directory). However, I receive the following error:
" System.UnauthorizedAccessException: Access to the path [...] is denied. at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode) at [...] in [...] at _Default.Button1_Click(Object sender, EventArgs e) in [...]"
The application is running under IUSR_ [ServerName] and hence the same applies to the[Template] folder. As far as I know, the IUSR_[Servername] account has no file permission. I am using Win2003 server with IIS 6.0. What permissions should be granted to the[Templates] folder only to make the files readable. The code causing the error is as follows:
"
string FilePath = HttpContext.Current.Server.MapPath("~/Templates/Demo.htm");
if (File.Exists(FilePath))
{
FileStream f1 = new FileStream(FilePath, FileMode.Open);
StreamReader sr = new StreamReader(f1);
str = sr.ReadToEnd();
str = str.Replace("@my_user", "user");
str = str.Replace("@my_pass", "secret");
f1.Close();
}
// use str for further processing
"
Any help is appreciated.