我的网站上有一个管理员面板,允许用户将图像上传到文件系统.我只是在做C#代码:
imageFile.SaveAs(galleryPath + fileName);
Run Code Online (Sandbox Code Playgroud)
但获得权限异常:
访问路径'D:\ Hosting ...\html\Images\Gallery\page2-img1.jpg'被拒绝.
描述:执行当前Web请求期间发生未处理的异常.请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息.异常详细信息:System.UnauthorizedAccessException:拒绝访问路径'D:\ Hosting ...\html\Images\Gallery\page2-img1.jpg'.
能否请给我一个提示我如何授予权限?
我正在尝试使用 File.ReadAllText 和 FileStream 读取文本文件,但由于某种原因,我每次都收到 System.UnauthorizedAccessException。
class consultas
{
public consultas()
{
}
private string Inativos = @"C:\Users\Mathias Cruz\Desktop\helloWorld\helloWorld\Consultas";
public string getInativos()
{
try
{
// string path = Directory.GetCurrentDirectory();
this.Inativos = File.ReadAllText(this.Inativos);
}
catch(Exception e)
{
throw e;
}
return this.Inativos;
}
}
Run Code Online (Sandbox Code Playgroud)
为什么?我在该文件夹中有权限,为什么会出现此异常?