WebSharper 4 for ASP.NET MVC: new and improved

Loic Denuziere

Loic Denuziere

Mar 21, 2018

Reading time:

2 mins

Share via:

We are happy to announce the release of WebSharper 4.2.7, and with it, WebSharper.AspNetMvc 4.2.0. This layer for running WebSharper applications alongside ASP.NET MVC has been simplified compared to its previous 3.x incarnations.

About WebSharper.AspNetMvc

WebSharper.AspNetMvc is a small package that facilitates the integration of WebSharper in an existing ASP.NET MVC application.

You can see an example mixed application here. It demonstrates:

Learn more in the documentation.

Changes from v3.6

In WebSharper.AspNetMvc 3.x, in order to call Remote functions from an MVC page or to run a Sitelet whose URL supersedes an MVC controller, it was necessary to register WebSharper.AspNet.Filter with code such as the following:

public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
    filters.Add(new WebSharper.AspNetMvc.Filter());
}

The above code is not necessary anymore. In fact, the entire Filter class is now marked obsolete. Registering WebSharper's HTTP modules in Web.config is now sufficient, just like in ASP.NET non-MVC applications:

<!-- for IIS 7.0 and newer -->
<system.webServer>
  <modules>
    <add name="WebSharper.RemotingModule" type="WebSharper.Web.RpcModule, WebSharper.Web" />
    <add name="WebSharper.Sitelets" type="WebSharper.Sitelets.HttpModule, WebSharper.Sitelets" />
  </modules>
</system.webServer>

<!-- for IIS 6.0 -->
<system.web>
  <httpModules>
    <add name="WebSharper.RemotingModule" type="WebSharper.Web.RpcModule, WebSharper.Web" />
    <add name="WebSharper.Sitelets" type="WebSharper.Sitelets.HttpModule, WebSharper.Sitelets" />
  </httpModules>
</system.web>

The properties of Filter have either lost their purpose or been moved:

  • SiteletsOverrideMvc was used to decide what happens when both MVC and WebSharper are able to handle a given URL: if true (the default), then the WebSharper sitelet is invoked; otherwise, the MVC controller is invoked.

    This is now handled by the global static property WebSharper.Sitelets.HttpModule.OverrideHandler, introduced in WebSharper 4.2.7. If you need to customize this paramater, you should do so in the application's startup:

    public class MyMvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            WebSharper.Sitelets.HttpModule.OverrideHandler = false;
        }
    }
    
  • SiteletsModuleName and RemotingModuleName are not needed anymore.

The handling of client-side controls in Razor pages using WebSharper.AspNetMvc.ScriptManager remains unchanged; see the documentation for more information about it.

Happy coding!

Read more from

Can’t find what you were looking for? Drop us a line.

Loic Denuziere
Found a typo?

This blog post is hosted on GitHub here. Feel free to file a ticket or send a PR.

Newsletter

We will not spam you or give your details to anyone.