Skip to content
 

Starting Cassini manually

startingcar If you create Web sites with Visual Studio 2005/2008 using the file system, VS’s intrinsic Web server Cassini is used to host your Web app during development. Cassini is a handy improvement over using IIS for development—if for no other reason that its ability to run your projects without every needing to create a virtual directory. I’ve read some blog posts and other comments on the Web about Cassini causing issues during development. Some insist that it behaves differently than IIS. I have never had any such trouble with Cassini and think its advantages over IIS, at least for initial development, make Cassini worthwhile.

However, there is a minor downside to Cassini: You can’t run your projects as stand-alone applications. That is, by default Cassini only runs when Visual Studio is running. Traditionally, to get a Web app to run independent of Visual Studio, you’d need to create an IIS virtual directory. However, if you start Cassini manually, you can avoid the need for IIS for running your ASP.NET projects outside Visual Studio. By the way, do note that when I talk about running your projects independent of Visual Studio, I mean for testing purposes—under no circumstances would you or should you use Cassini as a production Web server. To start Cassini manually, use the DOS command line as shown in Figure 1:

Figure 1. DOS command line to start Cassini
  1 c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE 
  2     /port:8888 /path:"f:\_codewebclasswclist" /vpath:"/wclist" 

where /path indicates the physical path to the Web app and /vpath indicates the virtual path to the Web app. The port can be any value, but do make note of it. You need it to launch the app in your browser. When you start Cassini manually a DOS box appears and is visible while Cassini is running. Minimize this box if you find it annoying. To end Cassini, right-click the Cassini Web server icon in the notification area and select "stop" or just close the DOS box. After starting Cassini, to run your app, start your browser and use a URL as shown in Figure 2:

Figure 2. URL to launch Cassini-hosted app
  1http://localhost:8888/wclist/listcustomers.aspx

where the port you specify is the same as the one used to start Cassini. Note that the virtual path name provided (wclist, in this case) must match what you specified with Cassini’s /vpath argument. One place where this tip is helpful is when testing Web services. In order to test a client a Web service that you’ve created, that Web server needs to be running. You could start an instance of Visual Studio, and run the service from there, but by starting Cassini manually, you can avoid needing that second instance of Visual Studio. For each Web service project I create, I also create a batch file that starts and runs the Web service for testing—as shown in Figure 3.

Figure 3. Batch file to launch Cassini-hosted app
  1start http://localhost:8888/wclist/listcustomers.aspx 
  2C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE 
  3    /port:8888 /path:"f:\_codewebclasswclist" 
  4    /vpath:"/wclist" 

Notice that the browser is launched before Cassini is started (using the DOS Start command). This is because the batch file doesn’t process any lines after launching Cassini until Cassin ends. Generally, because Cassini starts so quickly, even though the browser starts first, the app displays normally in the browser. Occasionally you might have to click "refresh" in the browser is the app failed to load because Cassini took too long to load.

Use a standard TestPublish folder. You could run launch a Cassini instance over a Visual Studio’s project working folder, but this would take creating lots of batch files. I use a different strategy. I create a folder called "TestPublish" and then publish the Web site or Web service I want to test to that folder. The contents of this folder are fluid—changing as I’m in and out of testing various projects. I don’t care about this, as this folder is only for test purposes. A single batch file to start Cassini over this folder is all I need to run the latest project I’ve published there (as shown in Figure 4 below). For quick and dirty Web site deployment to the server, the contents of this folder (after local testing is complete) can be XCOPYed to the Web server for testing on the server.

Figure 4. Run a Cassini-hosted app from TestPublish folder
  1C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\WebDev.WebServer.EXE 
  2   /port:8888 /path:"f:\TestPublish" /vpath:"/TestPublish" 

Leave a Reply