C# (Mono) Linux Web Server Hosting with Consistent Static Variables Across Threads

C# (mono) Linux web server hosting with consistent static variables across threads

mod_mono does not spawn a new mono process for each new web request. Neither does it if you use the fastcgi server along with apache or nginx.

EDIT: Static variables are shared within the same Application Domain. This holds true for Microsoft .NET IIS and for mono (no matter if you are using mod_mono, xsp or mono-fastcgi-server). Even so apache spawns multiple worker threads and a single request is handled by a single worker thread, there is only a single mono process running at any given time (except if you have configured multiple asp.net applications, then there is one per application).

Mono tries to achieve 100% compatibility for ASP.NET as well, so there is no different behaviour by design!

The different behaviour of your program on linux is most likely not related to how mod_mono handles requests, but rather a bug in mono itself, or your code (i.e. by making a platform assumption that does not hold true on linux). You should really debug using MonoDevelop/xsp and try to pinpoint the problem more clearly, or paste some sample code here.

Different hosting option with NancyFX?

The Nancy documentation has a section on hosting which is a good place to start. It has sections on hosting Nancy apps on ASP.NET, WCF, Azure, Umbraco and self hosting.

As an aside I can mention that I've run Nancy on AppHarbor simply by using Nancy ASP.NET hosting and pushing that through Git to AppHarbor. No complications.

ServiceStack-based web site under Mono/Linux: Performance with static content

If you have an opportunity to, serve static files with nginx, that would always be the most efficient option.

It's also what www.servicestack.net does with a lot of their Live Demo's.

Mono and IHttpHandler

HTTP handlers and modules work fine in Mono.

Your problem is that your Web.config file use the syntax specific to the "Integrated Pipeline" mode of IIS. This mode doesn't exist under Apache/mod_mono. So you must use the old syntax (i.e. the one for the "Classic Pipeline" mode) and provide a <system.web/httpHandlers> section, in addition to the existing <system.webServer/handlers> section.

See this Web.config example :

<?xml version="1.0"?>
<configuration>
<system.web>
<httpHandlers>
<add path="*.rss" verb="*" type="CedricBelin.Web.FeedHandler" />
</httpHandlers>
</system.web>

<system.webServer>
<handlers>
<add name="Feed" path="*.rss" verb="*" type="CedricBelin.Web.FeedHandler" />
</handlers>

<validation validateIntegratedModeConfiguration="false" />
</system.webServer>
</configuration>

The <validation ...> tag is very important: if you forget it, IIS throws an error and complains that an unauthorized section is used in the Integrated Pipeline context.

The next step is to instruct the Apache server to transfer the handling of your files to mod_mono, like this :

<VirtualHost *:80>
ServerName mono.localhost
DocumentRoot "/Library/WebServer/Documents/MonoTest"
AddType application/x-asp-net .rss
</VirtualHost>

The line AddType application/x-asp-net .rss is the important one. See the relation between path="*.rss" in Web.config and .rss extension in this line.
If you want to handle all extensions, as in your example (path="*"), you must replace the line AddType application/x-asp-net .rss by ForceType application/x-asp-net.

Web hosting for Mono?

Mono Project Web Hosting should do:

The Mono Project (a.k.a. mod_mono) is an open-source .NET Framework emulation tool for Linux sponsored by Novell. Through Mono, we have assembled a simple and easy-to-use web hosting platform which bridges the gap which previously existed between Windows and Linux hosting providers. What was once properietary Microsoft technology has been made available to the open-source developer community, and supplied right here with our premium Linux hosting service.

How can I use Mono.WebServer (XSP) to run my mono ASP MVC application?

Just run xsp4 in the directory with your web application.



Related Topics



Leave a reply



Submit