Contents | (Visit Preferences to set your user name.) | Related To How To Create A CGI Executable That Is A .NET Console Application | RecentChanges | Preferences | Index | Login | Logout
Creating a .NET CGI Console Application
See other Tech Tips
CGI apps can simply be executables that look at their environent and STDIN for the web request, and return the web page, with headers, as output to STDOUT. It is possible to write a CGI application as a C# .NET console application.
One way to test an .EXE type CGI app is to run the application from a DOS prompt. You should see it output whatever its default page is.
However it is possible that an app that seems to run fine from the DOS prompt will generate errors when you try to run it as a CGI app launched by the IIS web server. This has happened when trying to get a simple example of a CGI written with .NET framework 2.0 to compile and run under IIS with Visual Studio 2005. One error you can get is:
Unhandled Exception: System.IO.FileLoadException?Create: Could not load file or assembly 'SimpleDotNetCGI?Create, Version=1.0.0.0, Culture=neutral, PublicKeyToken?Create=null' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG)) File name: 'SimpleDotNetCGI?Create, Version=1.0.0.0, Culture=neutral, PublicKeyToken?Create=null' ---> System.ArgumentException?Create: Invalid directory on URL. at System.Security.Policy.PolicyLevel?Create.GenericResolve?Create(Evidence evidence, Boolean& allConst) at System.Security.Policy.PolicyLevel?Create.Resolve(Evidence evidence, Int32 count, Char[] serializedEvidence) at System.Security.PolicyManager?Create.ResolveHelper?Create(Evidence evidence, PermissionSet?Create request, Boolean systemPolicy) at System.Security.HostSecurityManager?Create.ResolvePolicy?Create(Evidence evidence) at System.Security.PolicyManager?Create.Resolve(Evidence evidence, PermissionSet?Create request) at System.Security.SecurityManager?Create.ResolvePolicy?Create(Evidence evidence, PermissionSet?Create reqdPset, PermissionSet?Create optPset, PermissionSet?Create denyPset, PermissionSet?Create& denied, Boolean checkExecutionPermission?Create) at System.Security.SecurityManager?Create.ResolvePolicy?Create(Evidence evidence, PermissionSet?Create reqdPset, PermissionSet?Create optPset, PermissionSet?Create denyPset, PermissionSet?Create& denied, Int32& grantedIsUnrestricted?Create, Boolean checkExecutionPermission?Create)
When this error happens, the system will try to start the just in time debugger. But by default, this can not be done. Because of this, in the event view for system events, you'll see this error each time you try to start the app:
- Access denied attempting to launch a DCOM Server. The server is:
- {36BBB745-0999-4FD8-A538-4D4D84E4BD09}
- The user is IUSR_COMPUTERNAME2003/COMPUTERNAME2003, SID=S-1-5-21-108812876-3621918602-2350841271-1003.
Here are the details for this error:
- Details
- Product: Windows Operating System
- ID: 10002
- Source: DCOM
- Version: 5.0
- Component: System Event Log
- Symbolic Name: EVENT_RPCSS_LAUNCH_ACCESS_DENIED
- Message: Access denied attempting to launch a DCOM Server. The server is:
- %1
- The user is %2/%3, SID=%4.
Explanation
- A program, the Clsid displayed in the message, tried to start the DCOM server by using the DCOM infrastructure. Based on the security ID (SID), this user does not have the necessary permissions to start the DCOM server.
If you want to allow the system to start the just in time debugger, do the following:
User Action
Verify that the user has the appropriate permissions to start the DCOM server.
To assign permissions
- Using Regedit, navigate to the following registry value
HKCR\Clsid\clsid value\localserver32
The clsid value is the information displayed in the message.
- In the right pane, double-click Default.
The Edit String dialog box is displayed. Leave this dialog box open.
- Click Start, and then click Control Panel.
- Double-click Administrative Tools and then double-click Component Services.
- In the Component Services snap-in, navigate to Computers\My Computer\DCOM Config.
- In the right pane, locate the program by using its friendly name.
- In this case it was c:\windows\system32\vsjitdebugger.exe, the "Visual Studio Just-in-Time Debugger"
- Right-click the program name and then select Properties.
- On the Security tab, select Customize, and then click Edit.
- Add the user to the permissions list.
Now the visual studio just-in-time debugger can popup and tell you:
- Unhandled exception ('System.IO.FileLoadException?Create') occured in [SipleDotNetCGI 2Rel]?Create.exe [1260].
If you select visual studio, it will tell you:
- Could not load file or assembly '[SimpleDotNetCGI 2]?Create, Version=1.0.0.0, Culture=neutral, PublicKeyToken?Create=null' or one of its dependencies. The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Two of the troubleshooting tips are:
- Make sure that the file is a valid .NET Framework assembly
- Get general help for this exception
Unfortunately, this still doesn't get the program to run.
STATUS: Some kind of access rights problem in starting the app. Status: Unsolved
POSSIBLE FIX: Modify CGI app properties to give group Users "Full control" security permissions. Status: Worked for me
Other Related Links
Examples of simple .NET CGI applications:
Articles about CGI, IIS, .NET, etc
*http://geekswithblogs.net/kobush/
- UPDATED: After all the reinstallation (including VisualStudio?Create and all .NET Betas) I went to .NET 2.0 configuration panel and looked into Runtime Security Policy settings. There was an entry in User Code Groups titled VSTOProjects (I was playing with VisualStudio?Create Tools for Office day before). There was also entry for the sample project I created. Because I tried to restore everything to clean system I removed this entries. And that was it!
- So I guess the error was coming in fact not from any errors in my application but the security policy system couldn't initialize itself due to invalid entry (hence the error of “Invalid directory or url“).
- http://msdn.microsoft.com/library/default.asp?url=/library/en-us/secmod/html/secmod15.asp - How to create a least privileged account to run ASP.NET
Google searches:
- CGI .NET Console Application
- CGI .NET Console Application "Could not load file or assembly"
- "Invalid Directory On URL"
- "could not load file or assembly" iis cgi - nothing found
Bobsgear - Get A Free
Enterrpise Wiki Space!
Review: The Bobsgear Project was
started to develop a variety of Confluence
plugins. This installation of
the Confluence Enterprise wiki includes flexible
attachments, many Confluence plugins, personal blogs,
interesting articles, and more. Bobsgear already has spaces related to
politics, art and
photography wiki,
technical issues wiki,
ediscovery wiki, health,
Christian theology and Sabbath
School wiki, the
bible, book reviews,
and quotations. Bobsgear
allows free signup, and invites anyone to create a
free hosted Confluence wiki space.
NEW
USERS CLICK HERE! for a quick introduction to
Wiki.
Interested in Google Question - How Can I Get Google To Stop Showing A Copy Of My Site?