Showing posts with label WebDev.WebServer. Show all posts
Showing posts with label WebDev.WebServer. Show all posts

Sunday, February 22, 2009

Starting ASP.NET Development Web Server(Cassini) manually

For development, Visual Studio 2005 now comes with a built-in development-only Web server. This lightweight Web server can only respond to local requests and is therefore not a security threat. The server does, however support full debugging features and can be used as a development tool for new Web applications. When you are ready to test out scalability and performance or deploy for production, simply move the application to IIS.

If the asp.net application is not deployed in IIS and you try to run the asp.net application from Visual Studio 2005, the local development web server will be started automatically. If local web development server is automatically, it will pick up the port number randomly and run the development server in that port.

However, in some situations you might require to start this web server manually. For example, you might want to run this local web server in certain port or if you want to test the web page without opening VS 2005.

In those cases, you can use WebDev.WebServer.Exe located in

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50215 (this path might vary depending upon the .net framework installation) to start this web server manually. This is the executable for local development web server; even VS 2005 internally uses this executable to start the local web server.

This command line executable accepts three parameters,

1. path : Physical path of the application which you want to run.

2. port : port in which you want to start this web server. Default is 80.

3. vpath: Specify application root using this option. Default is "/"

For example, to start a web application located at c:\temp\testing and in the port 8001.

WebDev.WebServer.EXE /path:D:\temp\Testing /port:8001 /vpath:/testing

After you run this utility, you can see ASP.NET development Web server in the system tray. You can access your web application from the browser using http://localhost:8001/testing/

Get Development Server VPath And Port From Project File

private static void GetDevelopmentServerVPathAndPortFromProjectFile(
string csprojFileName,
out string developmentServerVPath,
out int developmentServerPort)
{
XPathDocument doc = new XPathDocument(csprojFileName);
XPathNavigator navigator = doc.CreateNavigator();

XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
manager
.AddNamespace("msbuild",
"http://schemas.microsoft.com/developer/msbuild/2003");

const string xpath = "/msbuild:Project/msbuild:ProjectExtensions/"
+ "msbuild:VisualStudio/msbuild:FlavorProperties/"
+ "msbuild:WebProjectProperties";

XPathNavigator webProjectPropertiesNode =
navigator
.SelectSingleNode(xpath, manager);
XPathNavigator developmentServerPortNode =
webProjectPropertiesNode
.SelectSingleNode("msbuild:DevelopmentServerPort",
manager
);
XPathNavigator developmentServerVPathNode =
webProjectPropertiesNode
.SelectSingleNode("msbuild:DevelopmentServerVPath",
manager
);

developmentServerPort
= developmentServerPortNode.ValueAsInt;
developmentServerVPath
= developmentServerVPathNode.Value;
}

private static string GetCommonProgramFilesPath()
{
string commonProgramFiles =
Environment.GetEnvironmentVariable("CommonProgramFiles(x86)");
if (string.IsNullOrEmpty(commonProgramFiles))
{
commonProgramFiles
=
Environment.GetEnvironmentVariable("CommonProgramFiles");
}
if (string.IsNullOrEmpty(commonProgramFiles))
{
commonProgramFiles
=
Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles);
}
return commonProgramFiles;
}

private static Process PrepareCassiniProcess(int developmentServerPort,
string projectPhysicalPath,
string developmentServerVPath)
{
string commonProgramFiles = GetCommonProgramFilesPath();
string cassiniPath = Path.Combine(commonProgramFiles,
@
"Microsoft Shared\DevServer\9.0\WebDev.WebServer.exe");
string cassiniArgs = string.Format(
CultureInfo.InvariantCulture,
"/port:{0} /nodirlist /path:\"{1}\" /vpath:\"{2}\"",
developmentServerPort
, projectPhysicalPath, developmentServerVPath);

Process cassiniProcess = new Process();
cassiniProcess
.StartInfo.FileName = cassiniPath;
cassiniProcess
.StartInfo.Arguments = cassiniArgs;
return cassiniProcess;
}

//
To use it, you need to discover the path to the CSPROJ file of the web
// project under test. I'll leave that as an exercise for the reader

Source : http://stackoverflow.com/questions/328566/starting-asp-net-development-web-server-cassini-as-part-of-unit-test-setup

HowTo Use Microsoft .NET ASP.NET Development Server as Standalone Web Server

Hi,

A little post in order to explain howto use ASP.NET Development Server as Standalone Web Server.

First of all where is located the ASP.NET Development Server on your computer ?

On Windows XP :

C:\WINDOWS\Microsoft.NET\Framework\[VERSION]\WebDev.WebServer.exe

On Windows Vista :

C:\Program Files\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.exe

You can now use it to start Standalone Web Application for local Presentation for example or for your ASP.NET Product Demo.

Here is the different's parameters in order to start your standalone Web Server

WebDev.WebServer /port: /path: /vpath:

Port Number : Between 1 and 65535 (Default is 80)
Physical Path : A valid directory on your hard disk where is located your Web Site
Virtual Path : A virtual path for your Web Application (Default is '/')

Here is a example of starting standalone Web Site by command-line :

WebDev.WebServer /port:8080 /path:"D:\WebSite" /vpath:"/MyApplication"

Cassini Wrapper (aka Web Dev WebServer)

Project Description
A '3-click away' ASP.Net webserver cassini (or 'Web Dev WebServer' for its new name)

1/ Right-Click on any folder in any standard screen (Explorer, DialogBox ...)
2/ Choose to start the web server from this folder
3/ Confirm the TCP/IP port to listen to.


Developed for the .NET Framework version 2.
Localized in English (Default) and French.

Integrated in Windows Shell (Right-click option on folders) via the installer.


link : http://www.codeplex.com/CassiniWrapper

code for the command line exe

here's the code for the command line exe:

using System;
using System.Windows.Forms;
using System.Diagnostics;

namespace OpenCassini
{
class Program
{
///
/// The main entry point for the application.
///

[STAThread]
static void Main(string[] args)
{
string path;

string command =
@"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE";
string commandArgs = string.Empty;

Random r = new Random();

string port = r.Next(1024, 9000).ToString();

if(args.Length == 1){
//grab the original path
path = args[0];

commandArgs += " /path:\"" + path + "\"";
commandArgs += " /port:";
commandArgs += port;
commandArgs += " /vpath: \"/";
commandArgs += path.Substring(path.LastIndexOf('\\') + 1);
commandArgs += "\"";

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();

info.Arguments = commandArgs;
info.CreateNoWindow = true;
info.FileName = command;
info.UseShellExecute = false;
info.WorkingDirectory = command.Substring(0, command.LastIndexOf('\\'));


Process.Start(info);

using(Control c = new Control()){
Help.ShowHelp(c, "http://localhost:" + port + "/");
}
}
}
}
}


Using Help.ShowHelp has the side effect of opening the default browser instead of just IE.

"ASP.NET 2.0 Web Server Here" Shell Extension

"ASP.NET 2.0 Web Server Here" Shell Extension

http://weblogs.asp.net/rmclaws/archive/2005/10/25/428422.aspx

I've been doing some web development work again lately, and I haven't wanted to screw with setting up IIS on my virtual machine. The .NET Framework 2.0 comes with a built-in webserver, based on the old Cassini web server. So I wanted to be able to easily set up any directory to have its contents served up on an as-needed basis. The result is an addition to the Windows Explorer right-click menu, as shown below:

This is enabled by a simple modification to the registry. You can take the text below and dump it into a file named "WebServer.reg", and then run it, to immediately get the item in the context menu.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\VS2005 WebServer]
@="ASP.NET 2.0 Web Server Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\VS2005 WebServer\command]
@="C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\Webdev.WebServer.exe /port:8080 /path:\"%1\""

There are a couple caveats to this tool, however:

  1. The web server does not randomly assign a port number, so it has to be hard-coded into the registry.
  2. The web server does not automatically assign a virtual directory, so it will always be "http://localhost:port"
  3. A command prompt window will be spawned, and cannot be closed without closing the web server process.

Moving foward, there are a couple of options to fix these issues:

  1. Someone who knows more about variables in the registry can help me fix issues #2 and #3
  2. I can build a wrapper executable that solves all three problems
  3. Microsoft can put in a DCR and fix it before it goes gold in a few days.

#3 is not likely, so I'd love to hear what you think. Hope this trick is useful.

VS2008 Web Server Here Shell Extension

VS2008 Web Server Here Shell Extension


UPDATE: Updated the registry settings per James Curran’s comment. Thanks James!

One of the most useful registry hacks I use on a regular basis is one Robert McLaws wrote, the “ASP.NET 2.0 Web Server Here” Shell Extension. This shell extension adds a right click menu on any folder that will start WebDev.WebServer.exe (aka Cassini) pointing to that directory.

Webserver-Here

I recently had to repave my work machine and I couldn’t find the .reg file I created that would recreate this shell extension. When I brought up Robert’s page, I noticed that the settings he has are out of date for Visual Studio 2008.

Here is the updated registry settings for VS2008 (note, edit the registry at your own risk and this only has the works on my machine seal of approval).

32 bit (x86)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VS2008 WebServer]
@="ASP.NET Web Server Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VS2008 WebServer\command]
@="C:\\Program Files\\Common Files\\microsoft shared\\DevServer
\\9.0\\Webdev.WebServer.exe /port:8080 /path:\"%1\""

64 bit (x64)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VS2008 WebServer]
@="ASP.NET Web Server Here"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\VS2008 WebServer\command]
@="C:\\Program Files (x86)\\Common Files\\microsoft shared\\DevServer
\\9.0\\Webdev.WebServer.exe /port:8080 /path:\"%1\""

For convenience, here is a zip file containing the reg files. The x64 one I tested on my machine. The x86 one I did not. If you installed Visual Studio into a non-standard directory, you might have to change the path within the registry file.

WebDev.WebServer Copy to another PC


WebDev.WebServer Copy to another PC


You need 3 files

1. \WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE
2. \WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.exe.manifest
3. \Windows\assembly\GAC_32\WebDev.WebHost\8.0.0.0__b03f5f7f11d50a3a\WebDev.WebHost.dll

no:3. you can’t copy with windows explorer, go to console and copy it

Using WebServer.WebDev For Unit Tests

Using WebServer.WebDev For Unit Tests

ASPX Web Server

If you cannot or do not want to use IIS as your Web server, you can still test your ASP.NET pages by using the ASPX Web Server.

About
The ASPX Web Server is a standalone web server written in C# that can be used to run your ASP.NET applications with minimal effort.

Features
  • You are developing ASP.NET Web pages while working with Windows XP Home Edition, which does not support IIS.
  • The ASP.NET Web Server only accepts authenticated requests on the local computer. This requires that the server can support NTLM or Basic authentication.
  • Hosts and runs multiple ASP.NET applications.
  • ASPX Web Server fully supports all ASP.NET features.
  • Can guarantee that the port you specify will be available when you run your ASP.NET applications.
  • Windows Shell integration, one click to run ASP.NET applications.

Running the ASPX Web Server

Run by command line :

ASPX.WebServer.exe /port: /path: /vpath:/open
Command line options
  • Port number : Between '1' and '65535' (Default is '80') or use 'auto' to use dynamic port
  • Physical Path : A valid directory on your hard disk where is located your Web Site
  • Virtual Path : A virtual path for your Web Application (Default is "/")
  • Open : auto open in web browser

Here is a example of starting standalone Web Site by command-line :

ASPX.WebServer.exe /port:auto /path:"D:\WebSite" /vpath:"/MyApplication" /open

Running the ASPX Web Server

Running the ASPX Web Server

Run by command line :

ASPX.WebServer.exe /port: /path: /vpath:/open
Command line options
  • Port number : Between '1' and '65535' (Default is '80') or use 'auto' to use dynamic port
  • Physical Path : A valid directory on your hard disk where is located your Web Site
  • Virtual Path : A virtual path for your Web Application (Default is "/")
  • Open : auto open in web browser

Here is a example of starting standalone Web Site by command-line :

ASPX.WebServer.exe /port:auto /path:"D:\WebSite" /vpath:"/MyApplication" /open