Click here to Skip to main content
15,860,972 members
Articles / Web Development / ASP.NET

Running ASP.NET websites outside of IIS

Rate me:
Please Sign up or sign in to vote.
4.60/5 (15 votes)
22 Apr 2009CPOL3 min read 44.5K   496   55   12
Running ASP.NET websites outside of IIS

Introduction

Ever come across the need to demo your ASP.NET website on a PC that didn't have IIS installed or access to the internet? OK here is a simple application that can do exactly that. Using the internal web server that Visual Studio uses to run and debug websites could also be used outside Visual Studio to run your web sites on it. However there are many more uses for the internal web server that is included in Visual Studio if you can think of it.

Background 

The internal web server is a nifty little thing that Microsoft created to run and debug applications inside Visual Studio. Before that, developers needed to deploy and test their code on a web server that they had on their desktop or worse, somewhere on a development server. The internal web server is based on the Cassini web server, but with many changes to it and built for .NET 2.0. So if this can solve developer woes from not needing to deploy and test on the web server, why not take it to the next level and use it to demo the applications. Again you may be able to get away with hosting it on a web server but just in case you needed a back up when there was no access to the internet!

Requirements

  1. Firefox - If you are using Internet Explorer, change the browser settings in the config file.
  2. Check to see if you have the WebDev.WebServer.Exe under  C:\Windows\Microsoft.NET\Framework\v2.0.50727

You can also package the WebDev.WebServer.Exe by including it under this project and change the path "WebDev" in the config to point to this folder.

How It Works? 

I have kept this really simple so there is a Browse button to help you navigate to the website folder you want to run and a Start button to start the web server and load the site. It also opens the browser and points to the URL. Basically the application is just a wrapper for the WebDev.WebServer.Exe file. 

RunWebSites

Using the Code 

Firstly you will need to start the web server, assign the port and point to the website folder. The following code does exactly that. I have stored the path and the port in the config file so you can easily change it. As you can see, I am using an anonymous method inside the thread to avoid dealing with thread parameter passing. The threads themselves are set to run in the background. I am using the process tool which helps in starting, stopping, controlling and monitoring applications to start the web server and the browser.

C#
try
{
    Thread th = new Thread(
    delegate()
    {
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = ConfigurationManager.AppSettings["WebDev"].ToString();
        proc.StartInfo.Arguments = " /port:" + 
		ConfigurationManager.AppSettings["Port"].ToString() + 
		" /path:" + WebSitePhysicalPath;
                        proc.Start();
    }
    );
    th.IsBackground = true;
    th.Start();
}
catch (Exception Ex)
{
    Lab_Status.Text = "Error starting web server : " + Ex.Message;
}

Once the Web server has been started and your website loaded, you will need to start your browser and point to the website.

C#
private void startBrowser() 
{
     try
     {
          Thread th = new Thread(
          delegate()
          {
               System.Diagnostics.Process proc = new System.Diagnostics.Process();
               proc.EnableRaisingEvents = false;
               proc.StartInfo.FileName = 
		ConfigurationManager.AppSettings["Browser"].ToString();
               proc.StartInfo.Arguments = "http://localhost:" + 
		ConfigurationManager.AppSettings["Port"].ToString();
               proc.Start();
          }
          );
          th.IsBackground = true;
          th.Start();
     }
     catch (Exception Ex)
     {
           Lab_Status.Text = "Error starting browser : " + Ex.Message;
     }
}

Points of Interest

There may be license implications about distributing the Webdev.WebServer, I haven't done much research into this. If it is part of the .NET 2.0 Framework distributable, then I don't think it should be much of a hassle as most Win XP boxes and higher, I am sure, have the .NET 2.0 and above framework. Again this is not to say I have taken into consideration all PCs. You could further extend this application to check if the WebDev.WebServer is installed on the machine.

Obviously I have not tested this for all possible scenarios so its usage might be limited.

You can also try this out in a batch file or with command line options.

History 

  • 22nd April, 2009: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Infosolvex Solutions Inc
Australia Australia
Ritesh is an IT consultant with over ten years of experience in the IT industry varying from consultation, architecture, design, development to technical management. He has a strong background in solutions and applications architecture with a focus on Microsoft’s .Net platform. His area of expertise spans design and implementation of client/server, database and web-based systems. He has worked with C#, ASP.NET 1.1 and 2.0, ADO.NET, Web Services and SQL technology on several enterprise class projects.




Freedom is not worth having if it does not include the freedom to make mistakes.
Mahatma Gandhi

Comments and Discussions

 
Generalvery good article and find Pin
Donsw12-Jun-09 16:42
Donsw12-Jun-09 16:42 
GeneralNice! Pin
SavDawg28-Apr-09 22:32
professionalSavDawg28-Apr-09 22:32 
GeneralI like this! Pin
tystent28-Apr-09 9:22
tystent28-Apr-09 9:22 
Questionhow to turn off or un-do WebDev.WebServer.Exe file Pin
OnTracksuite27-Apr-09 21:48
OnTracksuite27-Apr-09 21:48 
AnswerRe: how to turn off or un-do WebDev.WebServer.Exe file Pin
Ritesh Ramesh27-Apr-09 22:02
Ritesh Ramesh27-Apr-09 22:02 
GeneralArticle on assumptions, bad idea!!! Pin
Rahul D.27-Apr-09 18:46
Rahul D.27-Apr-09 18:46 
GeneralRe: Article on assumptions, bad idea!!! Pin
Ritesh Ramesh27-Apr-09 19:10
Ritesh Ramesh27-Apr-09 19:10 
GeneralRe: Article on assumptions, bad idea!!! Pin
Rahul D.27-Apr-09 19:31
Rahul D.27-Apr-09 19:31 
GeneralRe: Article on assumptions, bad idea!!! Pin
Ritesh Ramesh27-Apr-09 19:47
Ritesh Ramesh27-Apr-09 19:47 
GeneralRe: Article on assumptions, bad idea!!! Pin
davenaylor200016-Sep-09 0:41
davenaylor200016-Sep-09 0:41 
GeneralYou got my 5 ;-) Pin
ndinges24-Apr-09 6:40
ndinges24-Apr-09 6:40 
GeneralRe: You got my 5 ;-) Pin
Jeff Circeo27-Apr-09 21:45
Jeff Circeo27-Apr-09 21:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.