首页 > 解决方案 > 访问自定义 asp.net 应用程序配置文件时出现 DirectoryNotFoundException

问题描述

我有一个 ASP.NET MVC 应用程序,有时会在应用程序类别下的 Windows 事件日志中抛出以下消息错误(敏感数据已被其他字符串替换):

事件 ID:1309 - 来源:ASP.NET 4.0.30319.0

Event code: 3005 
Event message: Excepción no controlada. 
Event time: 10/11/2020 11:28:40 
Event time (UTC): 10/11/2020 10:28:40 
Event ID: dd36b383da324e25b95f955f7d784971 
Event sequence: 627 
Event occurrence: 1 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/2/ROOT-6-132494775147792163 
    Trust level: Full 
    Application Virtual Path: / 
    Application Path: C:\inetpub\wwwroot\MyAspMvcApp\ 
    Machine name: MyServer 
 
Process information: 
    Process ID: 4316 
    Process name: w3wp.exe 
    Account name: MyDomain\MyCustomIdentity 
 
Exception information: 
    Exception type: DirectoryNotFoundException 
    Exception message: No se puede encontrar una parte de la ruta de acceso 'C:\inetpub\wwwroot\MyAspMvcApp\bin\AppConfig.config'.
   en MyCompany.ApplicationData.Utils.ReadOrdersFolder() en d:\Projects\IntranetModule\Orders\Areas\Order\Controllers\OrderController.cs:línea 37
   en MyCompany.Controls.MyController.OnException(ExceptionContext filterContext)
   en System.Web.Mvc.Controller.System.Web.Mvc.IExceptionFilter.OnException(ExceptionContext filterContext)
   en System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception)
   en System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   en System.Web.Mvc.Controller.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   en System.Web.Mvc.Controller.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   en System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   en System.Web.Mvc.MvcHandler.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   en System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   en System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   en System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   en System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

 
 
Request information: 
    Request URL: http://my.aspnetmvcapp.com/Order/Order/ViewOrderAjax 
    Request path: /Order/Order/ViewOrderAjax
    User host address: 172.XX.X.XX 
    User: MyDomain\oneDomainUser
    Is authenticated: True 
    Authentication Type: Negotiate 
    Thread account name: MyDomain\MyCustomIdentity
 
Thread information: 
    Thread ID: 144 
    Thread account name: MyDomain\MyCustomIdentity 
    Is impersonating: False 
    Stack trace:    en MyCompany.ApplicationData.Utils.ReadOrdersFolder() en d:\Projects\IntranetModule\Orders\Areas\Order\Controllers\OrderController.cs:línea 37
   en MyCompany.Controls.MyController.OnException(ExceptionContext filterContext)
   en System.Web.Mvc.Controller.System.Web.Mvc.IExceptionFilter.OnException(ExceptionContext filterContext)
   en System.Web.Mvc.ControllerActionInvoker.InvokeExceptionFilters(ControllerContext controllerContext, IList`1 filters, Exception exception)
   en System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.<BeginInvokeAction>b__5(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   en System.Web.Mvc.Controller.<>c.<BeginExecuteCore>b__152_1(IAsyncResult asyncResult, ExecuteCoreState innerState)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   en System.Web.Mvc.Controller.<>c.<BeginExecute>b__151_2(IAsyncResult asyncResult, Controller controller)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   en System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   en System.Web.Mvc.MvcHandler.<>c.<BeginProcessRequest>b__20_1(IAsyncResult asyncResult, ProcessRequestState innerState)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   en System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   en System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   en System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   en System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   en System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step)
   en System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 
 
Custom event details: 

此时我要做的是访问“C:\inetpub\wwwroot\MyAspMvcApp\bin\AppConfig.config”文件以读取标签,具体来说,就是放置订单的文件夹路径。

AppConfig.config 是一个简单的 XML 文件。此外,路径“C:\inetpub\wwwroot\MyAspMvcApp\bin”和配置文件 AppConfig.config 始终存在。

此错误并非总是发生,只会发生几次。

我已将 C:\inetpub\wwwroot\MyAspMvcApp\ 的完整权限授予我的应用程序池标识 MyDomain\MyCustomIdentity,并且我已授予 IIS_IUSRS 读取和执行、显示文件夹内容和读取权限。注意:未授予 IUSR 用户访问此文件夹的权限。

任何想法为什么会发生这种情况?

标签: asp.net-mvcexceptioniisapplication-poolasp.net-4.5

解决方案


推荐阅读