How to give an exe the permissions it wants

I'm trying to write a c# CGI app.

When i simply use Console.WriteLine to output my results, everything is fine. But I want to use HTMLTextWriter and when I do, I get the following error below.

When I run the program in a console it works fine, but not when I access it from a browser. The directory has read/execute permissions for the IIS user account, and I've explicitly stated

[AspNetHostingPermission(SecurityAction.Demand,

Level = AspNetHostingPermissionLevel.Minimal)]

[AspNetHostingPermission(SecurityAction.InheritanceDemand,

Level = AspNetHostingPermissionLevel.Minimal)]

In my program. How then do I give my program the security permissions it needs to run

--Martin

Error Follows: ---------------------------------------------

The demand was for:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Level="Minimal"/>
</PermissionSet>

The granted set of the failing assembly was:
<PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Access="Open"/>
<IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Allowed="ApplicationIsolationByUser"
UserQuota="512000"/>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
<IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Window="SafeTopLevelWindows"
Clipboard="OwnClipboard"/>
<IPermission class="System.Security.Permissions.UrlIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Url="file:// /D:/My Documents/Visual Studio 2005/Projects/TestWebApp/TestWebApp/bin/Debug/TestWebApp.exe"/>
<IPermission class="System.Security.Permissions.ZoneIdentityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Zone="Internet"/>
<IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
version="1"
Level="SafePrinting"/>
</PermissionSet>

The assembly or AppDomain that failed was:
TestWebApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
The Zone of the assembly that failed was:
Internet
The Url of the assembly that failed was:
file:// /D:/My Documents/Visual Studio 2005/Projects/TestWebApp/TestWebApp/bin/Debug/TestWebApp.exe


Answer this question

How to give an exe the permissions it wants

  • schow

    When you run the exe from the command line instead of on the IIS server (I assume that's what you meant by "When I run the program in a console...") you have completely different permissions.  In all likelihood, when running in a console, you have FullTrust; when running in IIS, you're running in the "Internet" zone which has really no local file access (etc.).

    Even if you wanted to grant only the specific permissions that are failing (they may not be the only ones; just the only ones that have Demanded so far) you'd have to manually set each of those permissions for that particular assembly with the .NET configuration tool (in the Administration control panel applet).  I would suggest, since it sounds like an internal-use-only assembly that you've written (with no specific partial trust requirement), that you simply register that assembly in the GAC to give it FullTrust when running on that server.



  • Shun Yamaguchi

    I'm accessing it by having my local IIS serve the .exe to the client browser, just as I would a .cgi script.

    As to strongly named and registered in the GAC.. i have no idea. I'm basically just building it in VS2005 and my bin/debug directory is a virtual directory on IIS.

    The plan is for intranet use, on isolated networks (although that may change in the future) and I have admin rights to the server.. as it's currently my local machine.

    The thing that's confusing me is why using the HTMLTextWriter fails and using Console.writeline doesn't. Both are doing the same thing... that is outputting text.


  • Matt Brunell

    How are you accessing from a browser If it's a CGI app it should be accessed by the server in response to a browser request--is that what you mean

    Where are you adding this Demand attributes Assembly level, method level

    Keep in mind, just by adding Demand attributes doesn't mean your assembly will automatically get those permissions. Depending on whether the assembly is strong named, it's registered in the GAC, and the Framework configuration (e.g. where the assembly is run, etc.) your assembly won't be granted the permissions you want and the Demand attributes simply mean no code is ever executed in you assembly/method.

    What type of scenario are you using this assembly Internal use only or eventual plans to release to customers Do you have admin access to the server where you want to run this CGI



  • How to give an exe the permissions it wants