Running ASP.NET within a Command-Line .exe (Outside of IIS)
page 2 of 3
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 33975/ 167
Article Contents:

Code
One interesting use of this functionality is to “pre-process” dynamic ASP.NET requests – saving the output as static .htm files that you then prop onto a server. You can do this with MyHost.exe by “pipeing” the output automatically to a static file. For example:
      MyHost.exe Test.aspx > Test.htm

-------------------------------
MyHost.cs
----------------------------------------------
 
using System;
using System.IO;
using System.Web;
using System.Web.Hosting;
 
public class MyExeHost : MarshalByRefObject {
 
    public void ProcessRequest(String page) {
 
        HttpRuntime.ProcessRequest(new SimpleWorkerRequest(page, null, Console.Out));
    }
     
    public static void Main(String[] arguments) {
 
        MyExeHost host = (MyExeHost)ApplicationHost.CreateApplicationHost(typeof(MyExeHost), 
			"/foo", Directory.CurrentDirectory);
 
        foreach (String page in arguments) {
            
            host.ProcessRequest(page);
        }
    }
}
 
-------------------------------------------
Test.aspx
----------------------------------------
 
<html>
   <body>
      <h1> Hi DevLabs, 2 the time is now: <%=Now%> </h1>
   </body>
</html>

View Entire Article

Article Feedback

Title:  
Name:  
Url: ( Optional )
Comment:  
Please add 1 and 7 and type the answer here:

User Comments

Title: Invalid URI error   
Name: Sparky
Date: 5/1/2007 9:21:07 PM
Comment:
Hi, I keep getting "Invalid URI" errors when I try your example on either WinXP or Win2000. I'm struggling to find any other examples similar to yours - can you please advise why I'm getting this error?

Product Spotlight
Product Spotlight 






Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2009 ASPAlliance.com  |  Page Processed at 11/21/2009 6:15:06 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search