繁体   English   中英

当我在服务器上写入并保存文件时拒绝访问路径

[英]Access to path denied when i write and save the file on server

System.UnauthorizedAccessException: Access to the path 'C:\Inetpub\wwwroot\HealthCard\NewsTextFiles\News.html' 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, Boolean useLongPath)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access)

我正在使用ckeditor。 在服务器上编辑文件,然后在服务器上保存文件。 它不能在服务器上运行,但是可以在我的本地计算机上正常运行。

这是编辑和保存按钮的代码。

protected void btnSaveNews_Click(object sender, EventArgs e)
    {

        string str = Ckeditor.Text;

        string str1 = Server.HtmlDecode(str);

        //lblText.Text = str2;


        FileStream fs = new FileStream(Server.MapPath("~/NewsTextFiles/News.html"), FileMode.Create , FileAccess.Write);
        StreamWriter wr = new StreamWriter(fs);
        wr.Write(str1);


        wr.Dispose();
        fs.Dispose();

        pnleditor.Visible = false;
        upleditor.Update();
        upleditor.Visible = false;

    }

确保您的“应用程序池”用户以该文件/文件夹的写权限运行。

这可能是:

IIS_USRNetwork Service (也可以是其他服务)。

暂无
暂无

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

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