Search code examples
asp.net-coredotvvm

Add DotVVM to Asp.Net Core and Use existing Authentication and Authorization


Am working on an asp.net core application and it has some features already implemented . Am also using asp.net core Identity for authentication and authorization and have added functionaly for Admins to Add/Edit Users and assign claims. Now I want to gradually add and use dotvvm for some of the new functionalities yet to be implemented.

Thus is it possible to use the already existing Authentication and Authorization for the the features to be implemented in dotvvm?

I have seen this DotVVM Asp.net Core Authentication but not sure how that goes with existing the asp.net core Identity.


Solution

  • The infrastructure for authentication and authorization is not different from any other ASP.NET library.

    The only thing you need to do is to make sure that DotVVM is registered in the request pipeline after the authentication middlewares:

    app.UseCookieAuthentication(...);
    
    app.UseDotVVM(...);
    
    app.UseMvc(...);
    

    You can register it before MVC safely. DotVVM will pass all requests which are not matched by any of its routes to the next middleware in the pipeline.

    You can then use the [Authorize] attribute on viewmodels to disallow the users to enter the page.

    There is a sample application which combines DotVVM and ASP.NET MVC in one application. You can use the instructions to add DotVVM into an existing app.