FileNotFoundException IIS7

前端 未结 3 1481
执念已碎
执念已碎 2021-01-20 01:58

I have a C# Web app that runs perfectly fine in VS2010, but when deployed to an IIS7 server, returns the \"image not found icon\".

The piece of code in question ess

相关标签:
3条回答
  • 2021-01-20 02:47

    The IIS7 worker process runs under its own credentials. It will access the file as the identity that runs the Application Pool under which your website runs. This is usually ApplicationPoolIdentity or NetworkService. You need to grant that user access to the file in question.

    But if you are really getting a FileNotFoundException that is probably not your problem, so please post the entire stack trace.

    0 讨论(0)
  • 2021-01-20 02:50

    I think it is because you are accessing the image usin the mapped drive name. Instead if using T:\Published\Generic.jpg in IIS virtual directory try UNC name \machineName\Published\Generic.jpg

    0 讨论(0)
  • 2021-01-20 02:53

    I don't think that network drives are available under the context of a service. You will probably have to use a network share notation (such as \\machine-name\share). Additionally you are running under the default user context (IIS APPPOOL\ASP.NET v4.0), which is more difficult to get working in a network setup. You should change the application pool identity to a network user, and give that user access.

    Another option is to impersonate the user accessing the application (assuming you are using Windows Authentication).

    You can change the application pool identity by right clicking on the application pool and selecting advanced settings. Identity under the Process Model is the setting to change.

    In order to enable impersonation, you can go to the application, and select Authentication feature, enable ASP.NET Impersonation, then click Edit.. and ensure that Authenticated user is selected. Impersonation can also work with a particular user identity by using Specific User in this last dialog box, but that is mainly useful when you want to run in the context of a user that normally cannot run as a service.

    EDIT:

    Apparently the IIS AppPool users run under the machine context, which is DOMAIN\Machine$. See Application Pool Identities.

    0 讨论(0)
提交回复
热议问题