0

I have a .NET Framework 4.5 Website using Microsoft.Owin PhysicalFileSytem. In my workstation the website is running smoothly when hosting to IIS but when deploying to Windows Server IIS it throws a DirectoryNotFoundException. I'm using a shared folder as my network path in PhysicalFileSystem.

In the Windows Server I have already set the ApplicationPool Identity to Administrator account and set the Website Connect As to Administrator account

var fileSystem = new PhysicalFileSystem("\\10.12.50.40\Contents\");
                var options = new FileServerOptions
                {
                    FileSystem = fileSystem,
                    EnableDirectoryBrowsing = false,
                    RequestPath = "/InSysStorage/WebContent"
                };
app.UseFileServer(options);

Exception:

Server Error in '/InSysReport' Application. \10.12.50.40\Contents\ Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:

System.IO.DirectoryNotFoundException: \10.12.50.40\Contents\

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[DirectoryNotFoundException: \10.12.50.40\Contents]
Microsoft.Owin.FileSystems.PhysicalFileSystem..ctor(String root) +74
InSys.Report.Startup.Configuration(IAppBuilder app) in D:\TEAM PROJECTS\InSys.HRMS\Development\Solution\Web\InSys.Report\Startup.cs:29

[TargetInvocationException: Exception has been thrown by the target of an invocation.] System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +150
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +101 Owin.Loader.<>c__DisplayClass18_1.b__0(IAppBuilder builder) +66
Owin.Loader.<>c__DisplayClass9_0.b__0(IAppBuilder builder) +123
Microsoft.Owin.Host.SystemWeb.<>c__DisplayClass5_0.b__0(IAppBuilder builder) +81
Microsoft.Owin.Host.SystemWeb.OwinAppContext.Initialize(Action`1 startup) +462
Microsoft.Owin.Host.SystemWeb.OwinBuilder.Build(Action`1 startup) +40 Microsoft.Owin.Host.SystemWeb.OwinHttpModule.InitializeBlueprint() +70 System.Threading.LazyInitializer.EnsureInitializedCore(T& target, Boolean& initialized, Object& syncLock, Func`1 valueFactory) +115
Microsoft.Owin.Host.SystemWeb.OwinHttpModule.Init(HttpApplication context) +106
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +536
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +173
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296

[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +10043408 System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +95 System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254

Lance U. Matthews
  • 15,725
  • 6
  • 48
  • 68
  • I'm surprised `"\\10.12.50.40\Contents\"` worked without escaping the backslashes or using a verbatim `string`. Which `Administrator` account and password did you specify in the application pool? The one on the web server or the one on `10.12.50.40`? Are you able to connect/map to ``\\10.12.50.40\Contents\`` on the web server using `Command Prompt` or `Explorer` (i.e. not from a web process) using the same credentials? Also, it'd be helpful if you posted the exception details as text, not an image. – Lance U. Matthews Aug 14 '19 at 02:19
  • you can use impersonation, check this link https://stackoverflow.com/questions/249540/how-to-present-credentials-in-order-to-open-file – tofi lagman Aug 14 '19 at 02:19
  • @BACON its escaped in my code i just wrote that to be specific its actually \\\\10.12.50.40\\Contents\\ .. the Administrator account on the web server and yes i can open it in Explorer but i havent tried in Command Prompt – Rossu Belmonte Aug 14 '19 at 02:25
  • Ok, if you can connect from Explorer that at least establishes that it's not a problem with the credentials or the web server's network access to the file server. – Lance U. Matthews Aug 14 '19 at 02:32
  • thanks for the answering me @BACON, unfortunately I can't figure out a way to solve this. I moved my contents to the location of the Web Server. – Rossu Belmonte Aug 14 '19 at 07:13
  • I'm not familiar with that API so I can't comment on any complexities or nuances that might be contributing here. Just as another basic sanity check, are you able to add `System.IO.Directory.Exists(@"\\10.12.50.40\Contents\");` and `System.IO.Directory.GetFileSystemEntries(@"\\10.12.50.40\Contents\");` to your web code and see if those return expected values? – Lance U. Matthews Aug 14 '19 at 15:31
  • Also, you said you have the application pool set to use the _web_ (not file) server's `Administrator` credentials. Do the `Administrator` accounts on the web server and file server have the same password? When you were able to open the share from the web server using Explorer, were you logged into the web server as `Administrator` or another account? That is, did Explorer prompt you to enter credentials, or did it just work? – Lance U. Matthews Aug 14 '19 at 15:48

0 Answers0