开发者

error in reading a file

开发者 https://www.devze.com 2023-01-26 20:11 出处:网络
I\'m not able to open the file when I click on the link on page in MVC. I get the following message. I\'ve added the impersonation in the code. I\'m able to delete and save the file.

I'm not able to open the file when I click on the link on page in MVC. I get the following message. I've added the impersonation in the code. I'm able to delete and save the file.

Access to the path '\servername\folder1\folder2\folder3\foder4\filename.pdf' is denied.

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.UnauthorizedAccessException: Access to the path '......same as above....' is denied.

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has a base process identity (typically {MACHINE}\ASPNET on IIS 5 or Network Service on IIS 6) that is used if the application is not impersonating. If the application is impersonating via <identity impersonate="true"/>, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user.

To grant ASP.NET access to a file, right-click the file in Explorer, choose "Properties" and select the Security tab. Click "Add" to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.

Source Error:

Line 35:         ' This gets executed for every action on this controller
Line 36:         ViewData("READONLY") = IIf(SessionData.IsReadOnly, "Y", "N")
Line 37:         MyBase.Execute(requestContext)
Line 38:     End Sub
Line 39: 

Source File: C:\Posfx\trunk\posfx\camonline\Controllers\ApplicationController.vb Line: 37

Stack Trace:

[UnauthorizedAccessException: Access to the path '\\cambridge-uat-d\NetworkShare\DealDocumentShare\201102\online\136-test file 2.pdf' is denied.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7716623
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) +66
System.Web.HttpResponse.TransmitFile(String filename, Int64 offset, Int64 length) +134
System.Web.HttpResponse.TransmitFile(String filename) +12
System.Web.HttpResponseWrapper.TransmitFile(String filename) +11
System.Web.Mvc.FilePathResult.WriteFile(HttpResponseBase response) +37
System.Web.Mvc.FileResult.ExecuteResult(ControllerContext context) +268
System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +10
System.Web.Mvc.<>c__DisplayClass11.<InvokeActionResultWithFilters>b__e() +20
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
System.Web.Mvc.<>c__DisplayClass1开发者_高级运维3.<InvokeActionResultWithFilters>b__10() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +251
System.Web.Mvc.<>c__DisplayClass13.<InvokeActionResultWithFilters>b__10() +19
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +178
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +399
System.Web.Mvc.Controller.ExecuteCore() +126
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +27
Cambridge.Online.ApplicationController.Execute(RequestContext requestContext) in C:\Posfx\trunk\posfx\camonline\Controllers\ApplicationController.vb:37
System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +7
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContextBase httpContext) +151
System.Web.Mvc.MvcHandler.ProcessRequest(HttpContext httpContext) +57
System.Web.Mvc.MvcHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext httpContext) +7
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75


I think the error message is more than clear, it even tells you what to do which is rare. Your web site runs under a special account with limited privileges. Depending on the version of IIS you are using this account could vary. So you should consider granting read access to this account to the remote folder you are trying to access, which according to the exception you are getting is \servername\folder1\folder2\folder3\foder4.

You are saying that you've added impersonation, but impersonation works only for local resources. In your case it seems that you are trying to access a remote server (a remote share). In this case you need delegation and not impersonation. So you could configure your site to run under a domain account which has read access to this remote share.

0

精彩评论

暂无评论...
验证码 换一张
取 消