asp.net-mvc - 访问自定义 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 用户访问此文件夹的权限。
任何想法为什么会发生这种情况?
解决方案
推荐阅读
- android - RecyclerView 中 CardView 项的滚动位置
- c# - 即使禁用控件,ObjectListView 也允许垂直滚动?
- arrays - 将项目添加到角度材料表
- r - 初学者:在 R 中设置时间序列
- email - 垃圾邮件过滤器正在影响电子邮件打开率
- asynchronous - 使用 Camel 的异步非阻塞组播
- python - Sort array by specific column then sort by value of this column
- c# - 使用具有不同类型的多个对象反序列化 JSON 类
- azure - Azure DevOps - 从传入电子邮件创建工作项
- javascript - 在 overflow-x 为 auto 时设置 overflow-y 可见,以便内容可以垂直溢出父容器