【发布时间】:2017-11-27 16:21:04
【问题描述】:
我对 Windows 环境还很陌生,为了让我的 c# API 在 IIS 上工作,我付出了很多努力。我只设法在我的 Web API 上执行 GET。
当我尝试做一个 POST 时,我得到了这个:
{"Message": "An error has occurred.",
"ExceptionMessage": "Access to the path 'C:\\Path\\To\\API' is denied.",
"ExceptionType": "System.UnauthorizedAccessException",
"StackTrace": " at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)\r\n at System.IO.Directory.InternalCreateDirectory(String fullPath, String path, Object dirSecurityObj, Boolean checkHost)\r\n at System.IO.Directory.InternalCreateDirectoryHelper(String path, Boolean checkHost)\r\n at MiningAPI.Controllers.ValuesController.Post(HttpRequestMessage request) in C:\\Users\\Tavernier\\Desktop\\MiningReport\\MiningAPI\\MiningAPI\\Controllers\\ValuesController.cs:line 90\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"}
IUSRS 和 IIS_IUSRS 的权限完全可以读取 Web API 文件夹中的文件。
我在 Windows 10 上,运行 IIS-10
更新:
当我通过 Visual Studio 启动 Web API 时,POST 正在工作。 (localhost:port, 现在是 192.168.1.30:port)
我尝试将我的文件夹移动到D:,将NETWORK SERVICE 添加到权限中。
【问题讨论】:
-
你在
Post方法中做了什么?似乎您正在尝试操作文件,而应用程序池身份没有这样做的权限。 -
@Liam 您是否注意到这些说明适用于 IIS 5?
-
我的“POST”在
Body中接受参数,然后根据这些参数生成一个文件并发回一个网址。 (192.168.1.30/user/chart.html)
标签: c# asp.net iis asp.net-web-api iis-10