【问题标题】:exe file is unable to create txt file from IISexe 文件无法从 IIS 创建 txt 文件
【发布时间】:2014-01-10 12:10:28
【问题描述】:

我创建了一个 WebApi 项目,我在其中调用了一个 exe,即 Latlong2XY.exe,它将输入文件和输出文件作为参数。并返回我一个 .txt 作为输出文件。当我从 VS2012 IDE 执行应用程序时,它成功创建了所需的 txt 文件。但是,当我在 IIS 中发布相同的应用程序并运行它时,它无法创建 txt 文件。

似乎 IIS Express 正在创建 txt 文件,而 IIS 没有。

这似乎是一些权限问题。但不知道该怎么做。 我的代码是:

        int exitCode;
        // Prepare the process to run
        ProcessStartInfo start = new ProcessStartInfo();
        // Enter in the command line arguments, everything you would enter after the executable name itself
        start.Arguments = @"D:\RFD\InputFile.txt D:\RFD\Results.txt";
        // Enter the executable to run, including the complete path
        start.FileName = @"D:\RFD\Latlong2XY.exe";
        // Do you want to show a console window?
        start.WindowStyle = ProcessWindowStyle.Hidden;
        start.CreateNoWindow = true;

        // Run the external process & wait for it to finish
        using (Process proc = Process.Start(start))
         {
            proc.WaitForExit();

            // Retrieve the app's exit code
            exitCode = proc.ExitCode;

        }

IIS 设置为:

Windows 身份验证:禁用; 表单身份验证:禁用; 匿名身份验证:启用; .Net 模拟:已禁用。

我正在使用 ASP.NET v4.0 应用程序池。

【问题讨论】:

标签: c# asp.net iis file-permissions iis-express


【解决方案1】:

您需要为应用程序目录(托管文件在机器上的位置)提供提升的权限。 (通常为 C:\inetpub\wwwroot\YourAppName)

授予用户“IIS_USR”或与该名称接近的名称对该文件夹的写入权限。

【讨论】:

    【解决方案2】:

    是的。,当您从"Visual Studio IDE" 执行此类操作时,它将起作用,因为IDE 具有控制 (System.Diagnostics.Process.Start) 的 IO 操作的最低权限。

    当您从 IIS 转到 Web application 托管时,遗憾的是 IIS 没有内置这些​​权限设置。所以你需要设置权限来执行windows native operations

    注意:通过使用它,您将提供加密后的系统(服务器)用户名和密码。

    您可以使用Aspnet_setreg.exe 在Web Config 中设置Windows 身份验证权限。将在互联网上提供使用说明。

    在您的 webconfig 中添加以下行:

    <authentication mode="Windows"/>
    
    <identity impersonate ="true"  userName="registry:HKLM\SOFTWARE\YourAPPName\ASPNET_SETREG,userName" password="registry:HKLM\SOFTWARE\YOURAPPNAME\ASPNET_SETREG,password"/>
    

    我在开发“windows service Re-Start from web”时遇到的类似问题。我已经解决并以这种方式解决了相同的权限问题。

    这个答案可能并不完美。但这也是实现解决方案的一种方式

    【讨论】:

    • 亲爱的@RJK 感谢您的回答,我会尽力让您知道。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 1970-01-01
    • 2012-02-11
    • 2021-09-21
    相关资源
    最近更新 更多