【发布时间】:2018-04-17 05:41:59
【问题描述】:
我有一个 mvc asp 应用程序需要编辑一个名为 test.php 的文件 我在 LocalHost 中使用此方法没有任何错误,当我将其传输到服务器时出现此错误:
System.UnauthorizedAccessException:对路径“C:\Users\Administrator\Desktop\codeEditor\test.php”的访问被拒绝。在 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 在 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, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) 在 System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize, Boolean checkHost) 在 System.IO.File.InternalReadAllText(String path, Encoding encoding, Boolean checkHost) 在 System.IO .File.ReadAllText(String path) at ASP._Page_Areas_user_Views_php_dark_cshtml.Execute() in C:\Inetpub\vhosts\tutpersia.com\httpdocs\Areas\user\Views\php\dark.cshtml
我尝试使用 Plesk 或右键单击更改我的目录的权限,然后...但仍然是同样的错误
我想在我的应用中做的是:
string filePath = "C:\\Inetpub\\vhosts\\sth.com\\httpdocs\\test.php";
string text = System.IO.File.ReadAllText(filePath);
System.IO.File.WriteAllText(filePath, text+"sth");
谢谢大家
【问题讨论】:
-
你说的“转移到服务器”是什么意思?
-
您的错误消息和发布的代码不相加。
-
您的错误消息显示您试图访问桌面上的文件,而不是网站的文件夹
标签: c# asp.net-mvc security windows-server-2012