2010-11-23 10 views
1

Ich kann die Datei nicht öffnen, wenn ich auf den Link auf der Seite in MVC klicke. Ich bekomme die folgende Nachricht. Ich habe den Identitätswechsel im Code hinzugefügt. Ich kann die Datei löschen und speichern.Fehler beim Lesen einer Datei

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__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.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 
+0

Irgendeine endgültige Lösung mit dem vollständigen Quellcode, der daran arbeitet? – Kiquenet

+0

Es war lange zurück. Ich erinnere mich nicht richtig. Aber es war etwas mit IIS-Anwendungspool –

+0

Es ist schade, diese Frage wird nie eine Antwort sein. Vielleicht können Sie sich daran erinnern und Ihre eigene Frage beantworten, oder besser, Sie aktualisieren Ihre Frage mit allem, woran Sie sich erinnern können. – Kiquenet

Antwort

1

denke ich die Fehlermeldung mehr als klar ist, es sagt auch, was zu tun, was selten ist. Ihre Website wird unter einem speziellen Konto mit eingeschränkten Berechtigungen ausgeführt. Abhängig von der Version von IIS, die Sie verwenden, kann dieses Konto variieren. Sie sollten also in Betracht ziehen, diesem Remote-Ordner Lesezugriff auf den Remote-Ordner zu gewähren, auf den Sie zugreifen möchten. Je nach der Ausnahme, die Sie erhalten, lautet der Code \servername\folder1\folder2\folder3\foder4.

Sie sagen, Sie haben Identitätswechsel hinzugefügt, aber Identitätswechsel funktioniert nur für lokale Ressourcen. In Ihrem Fall scheint es, dass Sie versuchen, auf einen Remote-Server (eine Remote-Freigabe) zuzugreifen. In diesem Fall benötigen Sie Delegierung und keine Identitätswechsel. So können Sie Ihre Site so konfigurieren, dass sie unter einem Domänenkonto ausgeführt wird, das über Lesezugriff auf diese Remote-Freigabe verfügt.

+0

Danke für die Antwort. Ich benutze IIS 7. Ich gab dem Netzwerkdienst ein Vollzugriffsrecht für diesen Ordner. Ist es richtig oder nicht? Außerdem kann ich die Datei löschen und speichern, kann sie aber nicht lesen. –

+0

Sie können es löschen, aber Sie können es nicht lesen? Das ist wirklich merkwürdig. –

+0

@ user344394 - Das Netzwerkdienstkonto ist ein lokales Computerkonto und Sie können es nicht ordnungsgemäß auf dem Remote-Server gewähren. –