2014-09-26 67 views
1

我們必須從我們的ASP.NET MVC應用程序訪問Program Files文件夾(用於讀/寫操作)。如何通過ASP.NET MVC訪問Program Files文件夾

正如你所猜測; Windows不允許這樣做。我嘗試使用用戶ASPNET(ASP.NET機器帳戶)完全控制訪問權限到.NET錯誤日誌中建議的文件夾和文件,但它不起作用。

  • IIS:版本8.5.9600.16384 @的Windows 8.1 x64的
  • 管道模式:集成
  • 應用程序池:自定義(我們的定製應用程序池)

**這裏是.NET錯誤登錄:**

<!DOCTYPE html> 
 
<html> 
 

 
<head> 
 
    <title>Access to the path 'C:\Program Files (x86)\DENEME\DENEMETEXT.txt' is denied.</title> 
 
    <meta name="viewport" content="width=device-width" /> 
 
    <style> 
 
    body { 
 
     font-family: "Verdana"; 
 
     font-weight: normal; 
 
     font-size: .7em; 
 
     color: black; 
 
    } 
 
    p { 
 
     font-family: "Verdana"; 
 
     font-weight: normal; 
 
     color: black; 
 
     margin-top: -5px 
 
    } 
 
    b { 
 
     font-family: "Verdana"; 
 
     font-weight: bold; 
 
     color: black; 
 
     margin-top: -5px 
 
    } 
 
    H1 { 
 
     font-family: "Verdana"; 
 
     font-weight: normal; 
 
     font-size: 18pt; 
 
     color: red 
 
    } 
 
    H2 { 
 
     font-family: "Verdana"; 
 
     font-weight: normal; 
 
     font-size: 14pt; 
 
     color: maroon 
 
    } 
 
    pre { 
 
     font-family: "Consolas", "Lucida Console", Monospace; 
 
     font-size: 11pt; 
 
     margin: 0; 
 
     padding: 0.5em; 
 
     line-height: 14pt 
 
    } 
 
    .marker { 
 
     font-weight: bold; 
 
     color: black; 
 
     text-decoration: none; 
 
    } 
 
    .version { 
 
     color: gray; 
 
    } 
 
    .error { 
 
     margin-bottom: 10px; 
 
    } 
 
    .expandable { 
 
     text-decoration: underline; 
 
     font-weight: bold; 
 
     color: navy; 
 
     cursor: hand; 
 
    } 
 
    @media screen and (max-width: 639px) { 
 
     pre { 
 
     width: 440px; 
 
     overflow: auto; 
 
     white-space: pre-wrap; 
 
     word-wrap: break-word; 
 
     } 
 
    } 
 
    @media screen and (max-width: 479px) { 
 
     pre { 
 
     width: 280px; 
 
     } 
 
    } 
 
    </style> 
 
</head> 
 

 
<body bgcolor="white"> 
 

 
    <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1> 
 

 
      <h2> <i>Access to the path 'C:\Program Files (x86)\DENEME\DENEMETEXT.txt' is denied.</i> </h2></span> 
 

 
    <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif "> 
 

 
      <b> Description: </b>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. 
 

 
      <br><br> 
 

 
      <b> Exception Details: </b>System.UnauthorizedAccessException: Access to the path 'C:\Program Files (x86)\DENEME\DENEMETEXT.txt' is denied. 
 
<br><br>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 and IIS 7, and the configured application pool identity on IIS 7.5) that is used if the application is not impersonating. If the application is impersonating via &lt;identity impersonate=&quot;true&quot;/&gt;, the identity will be the anonymous user (typically IUSR_MACHINENAME) or the authenticated request user. 
 
<br><br>To grant ASP.NET access to a file, right-click the file in File Explorer, choose &quot;Properties&quot; and select the Security tab. Click &quot;Add&quot; to add the appropriate user or group. Highlight the ASP.NET account, and check the boxes for the desired access.<br><br> 
 

 
      <b>Source Error:</b> <br><br> 
 

 
      <table width=100% bgcolor="#ffffcc"> 
 
       <tr> 
 
        <td> 
 
         <code> 
 

 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code> 
 

 
        </td> 
 
       </tr> 
 
      </table> 
 

 
      <br> 
 

 
      <b>Stack Trace:</b> <br><br> 
 

 
      <table width=100% bgcolor="#ffffcc"> 
 
       <tr> 
 
        <td> 
 
         <code><pre> 
 

 
[UnauthorizedAccessException: Access to the path &#39;C:\Program Files (x86)\DENEME\DENEMETEXT.txt&#39; is denied.] 
 
    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +216 
 
    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, Boolean useLongPath, Boolean checkHost) +1430 
 
    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +211 
 
    System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) +210 
 
    System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) +22 
 
    System.IO.StreamWriter..ctor(String path) +125 
 
    Publisher.Test.WebApp.Controllers.HomeController.Index() +118 
 
    lambda_method(Closure , ControllerBase , Object[]) +79 
 
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +242 
 
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +39 
 
    System.Web.Mvc.Async.AsyncControllerActionInvoker.&lt;BeginInvokeSynchronousActionMethod&gt;b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) +12 
 
    System.Web.Mvc.Async.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) +139 
 
    System.Web.Mvc.Async.AsyncInvocationWithFilters.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3d() +112 
 
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass46.&lt;InvokeActionMethodFilterAsynchronouslyRecursive&gt;b__3f() +452 
 
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass33.&lt;BeginInvokeActionMethodWithFilters&gt;b__32(IAsyncResult asyncResult) +15 
 
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass2b.&lt;BeginInvokeAction&gt;b__1c() +37 
 
    System.Web.Mvc.Async.&lt;&gt;c__DisplayClass21.&lt;BeginInvokeAction&gt;b__1e(IAsyncResult asyncResult) +241 
 
    System.Web.Mvc.Controller.&lt;BeginExecuteCore&gt;b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +29 
 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111 
 
    System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +53 
 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +19 
 
    System.Web.Mvc.MvcHandler.&lt;BeginProcessRequest&gt;b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +51 
 
    System.Web.Mvc.Async.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) +111 
 
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +606 
 
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +288 
 
</pre></code> 
 

 
        </td> 
 
       </tr> 
 
      </table> 
 

 
      <br> 
 

 
      <hr width=100% size=1 color=silver> 
 

 
      <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.33440 
 

 
      </font> 
 

 
</body> 
 

 
</html> 
 
<!-- 
 
[UnauthorizedAccessException]: Access to the path &#39;C:\Program Files (x86)\DENEME\DENEMETEXT.txt&#39; is denied. 
 
    at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) 
 
    at 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, Boolean useLongPath, Boolean checkHost) 
 
    at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) 
 
    at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize, Boolean checkHost) 
 
    at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize) 
 
    at System.IO.StreamWriter..ctor(String path) 
 
    at Publisher.Test.WebApp.Controllers.HomeController.Index() 
 
    at lambda_method(Closure , ControllerBase , Object[]) 
 
    at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) 
 
    at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) 
 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<BeginInvokeSynchronousActionMethod>b__39(IAsyncResult asyncResult, ActionInvocation innerInvokeState) 
 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult) 
 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() 
 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() 
 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) 
 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() 
 
    at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) 
 
    at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) 
 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) 
 
    at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) 
 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) 
 
    at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) 
 
    at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult) 
 
    at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() 
 
    at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) 
 
-->

+0

你爲什麼要這麼做?你可以解釋嗎? – Leo 2014-09-26 08:46:11

+0

我們正在使用某種在線語音識別系統。我們的第三方組件在程序文件中,並且不能在其他地方使用。這是我們應該做的唯一方式。所以我們的mvc應用程序必須訪問程序文件...我知道它很爛。並不是最好的練習...... – 2014-09-26 08:49:34

回答

1

嘗試添加讀/寫權限˚F或:

IIS APPPOOL\*YOURAPPPOOLNAME* 
+0

謝謝你的回答。但沒有運氣......我嘗試通過帳戶添加權限:完全控制的「每個人」。現在正在工作。但是,添加每個人都不好,你知道...... – 2014-09-26 09:43:15

+0

@NAKRO是你在ApplicationPoolIdentity帳戶下運行你的網站,並在集成模式和IIS 7+下運行嗎? – 2014-09-26 09:47:50

+0

@NAKRO如果您從Windows上下文菜單添加權限並編寫ISS APPPOOL \ applicationpoolname,然後單擊checkNames,那麼您應該爲她的applicitonpoolname加下劃線。另外不要忘記,您必須添加最低級別文件夾C:\ Program Files(x86)\ DENEME \ – 2014-09-26 09:56:57

相關問題