DotVVM 1.1.6 with ASP.NET Core 2.0 support

Published: 8/29/2017 7:48:00 PM

We have just released DotVVM 1.1.6 to the official Nuget feed.

If you are using DotVVM.Owin, there are no significant changes in comparison to the previous release of DotVVM 1.1.5.

If you are on ASP.NET Core, this release means a lot because we had to change the dependencies and drop support for ASP.NET Core 1.x.

 

Support for .NET Standard 2.0 and ASP.NET Core 2.0

If you compare the dependencies of DotVVM.AspNetCore package, you can see that we have upgraded to .NET Standard 2.0, and the lowest supported version of ASP.NET Core is ASP.NET Core 2.0.

Dependency changes

 

Because of many API changes in the Microsoft.AspNet.Authentication and Microsoft.AspNet.Authorization packages (mainly the deprecation of the AuthenticationManager class, but not only that), it was difficult to support both ASP.NET Core 1.x and 2.0 at the same time.

We would have to create two separate NuGet packages for ASP.NET Core 1.x and ASP.NET Core 2.0, and there would be a significant overhead involved with testing all the possible combinations of frameworks and libraries.

 

Since most of our users use DotVVM with full .NET Framework and OWIN and a lot of users were waiting for .NET Core 2.0 and skipped the first .NET Core versions completely, we have decided to drop support for ASP.NET Core 1.x.

From DotVVM 1.1.6, we will support only OWIN and ASP.NET Core 2.0.

We are not happy to do this, but on the other hand we feel that the users who were not afraid to using ASP.NET Core 1.x in production won’t be afraid of upgrading to ASP.NET Core 2.0.

 

Upgrade Notes

We made sure that there are no breaking changes in you DotVVM code. The only breaking change of upgrading to ASP.NET Core 2.0 comes with the different way of configuration of authentication middlewares.

In ASP.NET Core 1.x, you did all the configuration in the Configure method:

app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme,

    Events = new CookieAuthenticationEvents
    {
        OnRedirectToReturnUrl = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
        OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
        OnRedirectToLogin = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
        OnRedirectToLogout = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
    },
    LoginPath = new PathString("/login")
});

 

In ASP.NET Core 2.0, you need to configure the middlewares in the ConfigureServices methods, and specify the default authentication scheme:

public void ConfigureServices(IServiceCollection services)
{
    services.AddAuthentication(sharedOptions =>
    {
        sharedOptions.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
    })
    .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options => {
        options.Events = new CookieAuthenticationEvents
        {
            OnRedirectToReturnUrl = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
            OnRedirectToAccessDenied = c => DotvvmAuthenticationHelper.ApplyStatusCodeResponse(c.HttpContext, 403),
            OnRedirectToLogin = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri),
            OnRedirectToLogout = c => DotvvmAuthenticationHelper.ApplyRedirectResponse(c.HttpContext, c.RedirectUri)
        };
        options.LoginPath = new PathString("/login");
    });

    services.AddDotVVM(options =>
    {
        options.AddDefaultTempStorages("Temp");
    });
}

Then you just need to add the authentication middleware:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    app.UseAuthentication();

    // use DotVVM
    app.UseDotVVM<DotvvmStartup>(env.ContentRootPath);

    // ...
}

 

We'd like to hear from you! Share your thoughts and ideas with us on our Gitter.

Tomáš Herceg

I am the CEO of RIGANTI, a small software development company located in Prague, Czech Republic.

I am Microsoft Most Valuable Professional and the founder of DotVVM project.