简体   繁体   English

在IIS 7.0中部署时,检索txt文件会导致错误

[英]Retrieval of txt file gives an error when deployed in IIS 7.0

I have a text file RHKLIS.txt which is placed in D:\\ drive . 我有一个文本文件RHKLIS.txt放在D:\\ drive中 I have found out some piece of code to retrieve the path of the text file and it is working fine while running in the local host . 我已经找到了一些代码来检索文本文件的路径,并且在本地主机上运行时工作正常 I have deployed the code in some test machine using IIS 7.0 and tried accessing the same code but its not retrieving its giving the error as Sql transaction has closed in the line if (!File.Exists(path)). 我已经在使用IIS 7.0的某些测试机中部署了代码,并尝试访问相同的代码,但是由于Sql事务已在if(!File.Exists(path))行中关闭,因此无法检索到该错误 So i got to know that path specified is an issue in the code.But still i am not aware of what type of error it is because there is a same text file placed in the D:\\ drive in the same test machine. 所以我知道指定的路径是代码中的问题。但是仍然我不知道这是什么类型的错误,因为在同一台测试机的D:\\驱动器中放置了相同的文本文件。

in web.config 在web.config中

<appSettings>

  <add key="LISpath" value="D:\RHKLIS.txt"/>

</appSettings>

.cs file .cs文件

   string path = ConfigurationManager.AppSettings["LISpath"].ToString(); 
   FileStream fs = null;
   if (!File.Exists(path))
   {
       fs = File.Create(path);
       fs.Close();
   }

   StreamWriter sw = File.AppendText(path);

   sw.WriteLine("O~" + billHospNo.Text.Trim() + "~ ~" + opBillNo.Text + "~" + billDate.Text + "~" + itemCode.Text + "~" + itemName.Text + "~" + p.Honourfic + "~" + p.Patient_Name + "~" + p.Gender + "~" + p.Age + "~" + "Y" + "~" + "~" + "~" + "~" + "~" + "~" + department.SelectedItem.ToString() + "~" + billDate.Text + "~" + itemDept.Value + "~" + deptName + "~" + yearOB + "~" + due);
   sw.Close();

This sounds like a security problem. 这听起来像一个安全问题。 Firstly, the file being on the root of D: would mean that you would have open the whole D: to the IIS server (not good practice). 首先,该文件位于D:的根目录下,这意味着您将向IIS服务器打开整个D :(不是很好的做法)。 Rather create a new folder, add the IIS_IUSRS user (with read & execute, List folder contents and Read permissions) - then put the file in that folder. 而是创建一个新文件夹,添加IIS_IUSRS用户(具有读取和执行,列出文件夹内容和读取权限)-然后将文件放入该文件夹。 Change the setting in the config file and that should work... 更改配置文件中的设置,这应该可以...

This is making the assumption you have you have full admin rights on the server. 这是假设您拥有服务器的完全管理员权限。

Right-click on the folder, select properties. 右键单击该文件夹,选择属性。 A property window of the folder will open - select the Security tag. 文件夹的属性窗口将打开-选择“安全性”标签。 You will see two lists - the top is for the users or groups and the bottom is the rights - click the Edit button under users. 您将看到两个列表-顶部是用户或组,底部是权限-单击用户下的“编辑”按钮。

Another widow will open - click the Add button - which will open another window. 另一个寡妇将打开-单击“添加”按钮-这将打开另一个窗口。 Make sure the locations is for the local machine and not a domain, then click advanced, and click the Find Now button. 确保这些位置适用于本地计算机而不是域,然后单击“高级”,然后单击“立即查找”按钮。 Look through the list until you see the IIS_IUSRS user and double-click on it. 浏览列表,直到看到IIS_IUSRS用户,然后双击它。 This will put the user in the bottom text filed of the selection window. 这会将用户置于选择窗口的底部文本字段中。 Just click ok and it will automatically give that user the required permissions for the folder - then just click on ok all the way until all the windows are closed. 只需单击“确定”,它将自动为该用户授予该文件夹所需的权限-然后,只需单击“确定”,直到关闭所有窗口即可。

I hope this helps... This allow read-only access to that folder from IIS. 希望对您有所帮助...允许从IIS对该文件夹进行只读访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM