在 IIS 中托管 ASP.NET Web 应用程序后,Process.Start 不起作用

发布于 2025-01-01 01:48:37 字数 1569 浏览 0 评论 0原文

我有一个返回 ac# 代码,用于将文件保存在服务器文件夹中并从该位置检索保存的文件。但这段代码在本地机器上运行良好。但是在 IIS 中托管应用程序后,我可以将文件保存在所需的位置。但我无法使用从该位置检索文件

Process.Start

会出现什么问题?我在谷歌上搜索过,我发现这可能是由于访问权限造成的。但我不知道具体的问题是什么以及如何解决这个问题?有人请帮我解决这个问题吗?

保存文件:

string hfBrowsePath = fuplGridDocs.PostedFile.FileName;
if (hfBrowsePath != string.Empty)
{
    string destfile = string.Empty;
    string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\\\";
    if (!Directory.Exists(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)))
       Directory.CreateDirectory(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1));
    FileInfo FP = new FileInfo(hfBrowsePath);

    if (hfFileNameAutoGen.Value != string.Empty)
    {
        string[] folderfiles = Directory.GetFiles(FilePath);
        foreach (string fi in folderfiles)
        File.Delete(fi);
        //File.Delete(FilePath + hfFileNameAutoGen.Value);
    }
    hfFileNameAutoGen.Value = PONumber + FP.Extension;
    destfile = FilePath + hfFileNameAutoGen.Value;
    //File.Copy(hfBrowsePath, destfile, true);
    fuplGridDocs.PostedFile.SaveAs(destfile);
}

检索文件:

String filename = lnkFileName.Text;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\";
FileInfo fileToDownload = new FileInfo(FilePath + "\\" + filename);
if (fileToDownload.Exists)
     Process.Start(fileToDownload.FullName);

I have a return a c# code to save a file in the server folder and to retrieve the saved file from the location. But this code is working fine in local machine. But after hosting the application in IIS, I can save the file in the desired location. But I can't retrieve the file from that location using

Process.Start

What would be the problem? I have searched in google and i came to know it may be due to access rights. But I don't know what would be exact problem and how to solve this? Any one please help me about how to solve this problem?

To Save the file:

string hfBrowsePath = fuplGridDocs.PostedFile.FileName;
if (hfBrowsePath != string.Empty)
{
    string destfile = string.Empty;
    string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\\\";
    if (!Directory.Exists(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)))
       Directory.CreateDirectory(FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1));
    FileInfo FP = new FileInfo(hfBrowsePath);

    if (hfFileNameAutoGen.Value != string.Empty)
    {
        string[] folderfiles = Directory.GetFiles(FilePath);
        foreach (string fi in folderfiles)
        File.Delete(fi);
        //File.Delete(FilePath + hfFileNameAutoGen.Value);
    }
    hfFileNameAutoGen.Value = PONumber + FP.Extension;
    destfile = FilePath + hfFileNameAutoGen.Value;
    //File.Copy(hfBrowsePath, destfile, true);
    fuplGridDocs.PostedFile.SaveAs(destfile);
}

To retrieve the file:

String filename = lnkFileName.Text;
string FilePath = ConfigurationManager.AppSettings.Get("SharedPath") + ConfigurationManager.AppSettings.Get("PODocPath") + PONumber + "\\";
FileInfo fileToDownload = new FileInfo(FilePath + "\\" + filename);
if (fileToDownload.Exists)
     Process.Start(fileToDownload.FullName);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋心╮凉 2025-01-08 01:48:37

看起来像是文件夹安全问题。您存储文件的文件夹、用户组必须具有修改访问权限。基本上有一个用户(不确定,但它是 IIS_WPG)在其下运行 IIS 进程,该用户属于 Users 组,该用户必须对您所在的文件夹具有修改访问权限正在做读写。

建议

  • 使用Path.Combine 创建文件夹或文件路径。
  • 您可以使用String.Format来创建字符串。
  • 如果您有重复的相同表达式,请创建局部变量,例如 FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)

希望这对您有用。

It looks like folder security issue. The folder in which you are storing the files, Users group must have Modify access. Basically there is user(not sure but it is IIS_WPG) under which IIS Process run, that user belongs to Users group, this user must have Modify access on the folder where you are doing read writes.

Suggestions

  • Use Path.Combine to create folder or file path.
  • You can use String.Format to create strings.
  • Create local variables if you have same expression repeating itself like FilePath.Substring(0, FilePath.LastIndexOf("\\") - 1)

Hope this works for you.

聊慰 2025-01-08 01:48:37

您可能必须向正在运行的应用程序池授予权限。请参阅此链接 http://learn.iis.net/page.aspx /624/application-pool-identities/

您还可以使用内置帐户的“LocalSystem”之一作为应用程序池标识,但它存在一些安全问题。

You may have to give permissions to the application pool that you are running. see this link http://learn.iis.net/page.aspx/624/application-pool-identities/

You can also use one of the built-in account's "LocalSystem" as application pool identity but it has some security issue's.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文