⬆️ ⬇️

My experience with the Microsoft Cassini web server

1. What is Cassini



Cassini is a simple and “lightweight” web server for MS Windows, which, as it is easy to guess, handles requests to static HTML pages and ASP.NET applications. At the time of this writing, Cassini is distributed as part of Visual Studio and Microsoft does not encourage (but does not prohibit) its use and distribution outside of Visual Studio. Microsoft does not provide technical support for Cassini outside of Visual Studio. However, there are cases when Microsoft included Cassini in the delivery of its products, for example, early versions of Microsoft CRM (now known in the market as Microsoft Dynamics CRM). In March 2006, Microsoft opened Cassini 2.1 source code under a fairly liberal license, which says that the code can be used for any commercial or noncommercial purpose, including the distributing derivative works.



At the time of this writing, I managed to find several alternative Cassini distributions:



In addition, online, you can find information on successful decompiling (and subsequent successful build for 32-bit and 64-bit platforms) versions of Cassini, distributed with Visual Studio.



Here are the main differences between Cassini and IIS:



In the process of working on one of the projects, I considered the option of using Cassini in demonstration web applications. In this document, an attempt is made to summarize the various information about Cassini found on the Web and personal experience.



2. Why Cassini? Why Cassini?



The project we were working on meant installing web applications and web services on the user's server. Unfortunately, it was not possible to guarantee the availability of IIS on the server (users are so different), so I had to turn my eyes on Cassini. The restrictions listed above did not bother us - it was only a demo application. The installation program of our product had to install Cassini and web applications on the user's machine so that immediately after installation the user could try the product in, going to localhost / SomeDemoApplication .

')

Looking ahead, I will say that everything turned out. But on the road came across a number of rakes, which I want to talk about.



3. Run Cassisni



I used Cassini executables from Visual Studio 2010 and built with .NET 4.0:



Starting Cassini was easy:



WebDev.WebServer40.exe /port:8111 /path:"c:\Projects\My Web Application"



and everything works: the address localhost : 8111 / Home.aspx shows me the home page of my web application.



Then I included the Cassini executables in the installer of our product with the installation of WebDev.WebHost40.dll in the GAC. The only problem that remains to be solved is the launch of Cassini before the user goes to the demo application page. A script was born here that uses a simple PortQry utility to determine Cassini activity on port 8111:



portqry.exe -n localhost -e 8111

if ERRORLEVEL=1 goto nolisten

echo Cassini is already running

goto end

:nolisten

start WebDev.WebServer40.exe /port:8111 /path:"c:\Projects\My Web Application"

:end

start localhost:8111/Home.aspx





It remains only to add the script to the installer and the shortcut for this script in the Start menu, and the setup is ready.



4. Problems



As always, it was not without questions.



WebDev.WebHost40.dll in the GAC


Actually, there is no big problem in this, but the question remains: why in general should this assembly be in the GAC? I did not look at Cassini’s sources, so I don’t know the true reason. If this is just a cheap way to get full-trust, then the next question will be: why do we need a full-trust toy web server? In general, I will feel more confident using Cassini in my products, if someone clearly explains why WebDev.WebHost40.dll is in the GAC.



64-bit support


At the time of writing, Visual Studio and Cassini are 32-bit applications. If you try to host a 64-bit ASP.NET application using Cassini, an exception will be thrown. You have two options: either recompile your ASP.NET application to 32 bits, or try using alternative Cassini distributions supporting 64 bits (see the list above).



Problem with virtual path


Cassini from Visual Studio has a convenient / vpath option that allows you to specify a virtual folder for your application. But when I tried to use this option when Cassini started and run my application from localhost : 8111 / MyAppVirtualFolder / Home.aspx, I received an error: WebConfigurationManager.OpenWebConfiguration () throwing “Failed to map the path '/'” exception. The only solution I found was to run Cassini with the / vpath option in elevated mode (elevated privileges), then the virtual path worked. This option is suitable for testing, but is hardly suitable for a commercial product. As in the case of the GAC, it would be interesting to get an explanation for this strange behavior.



5. Recommendations



There are times when Cassini can be extremely helpful, but it should be used with caution. Test the final solution in as many configurations as possible and never for a moment forget that Cassini is not a complete commercial product. Good luck!

Source: https://habr.com/ru/post/118620/



All Articles