1

We have to access Program Files folder (for read/write operations) from our ASP.NET MVC application.

As you can guess; Windows doesn't allow that. I tried to give full control access permission with user ASPNET (ASP.NET Machine Account) to the folder and files manually as suggested in .NET error log, but it's not working.

  • IIS: Version 8.5.9600.16384 @ Windows 8.1 x64
  • Pipeline Mode: Integrated
  • Application Pool: Custom ( Our custom application pool )

**Here is the .Net Error Log:**

<!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)
-->

2
  • why on earth do you want to do that???? Can you explain? Commented Sep 26, 2014 at 8:46
  • We are using some kind of online-voice-recognization system. Our 3rd party components in program files and doesn't work other places. This is the only way we should to do. So our mvc app must access to program files... I know it sucks. And it's not best practice at all... Commented Sep 26, 2014 at 8:49

1 Answer 1

1

Try to add read/write permissions for:

IIS APPPOOL\*YOURAPPPOOLNAME*
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your answer. But no luck... I tried adding permission via account: "Everyone" with full control. It's working now. But it's not good to add everyone, you know...
@NAKRO are you running your site under ApplicationPoolIdentity account and in Integrated mode and IIS 7+?
@NAKRO if you are adding permission from windows context menu and write the ISS APPPOOL\applicationpoolname then click on checkNames then you should she applicitonpoolname underlined. Also do not forget that you have to add permission for the lowest level folder C:\Program Files (x86)\DENEME\
I updated my question. IIS 8.5, Integrated Mode, Application Pool: Custom App Pool.
Ok it works! I added "IIS APPPOOL\MyLovelySite" with full control to the folder and subfolders/subfiles. Now it's working... Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.