39

Is it possible to self host asp.net mvc inside another application ie. console, windows forms, service etc etc.

I'd like to build an app that offers a web interface to control it and I'd like to use asp.net mvc for the web part of it.

I did take a quick look at Nancy which looks like it would work, though its not asp.net mvc it did support razor although it doesn't have quite the same level of support for it as asp.net (eg. strongly typed views)

I did also find this question but it doesn't really go into much depth Possible to use ASPNET MVC2 without IIS?

Community
  • 1
  • 1
Daniel Powell
  • 8,143
  • 11
  • 61
  • 108

3 Answers3

36

You can use "IIS 7.0 Hostable Web Core" and host the web server as part of any user process, even a console application. The benefit is that it is very similar to full blown IIS (incl config etc) but the web server itself is running in your process.

Have a look at the following articles:

  1. Host your own Web Server in your application using IIS 7.0 Hostable Web Core
  2. Creating Hosted Web Core Applications
bloudraak
  • 5,902
  • 5
  • 37
  • 52
11

Please have a look at http://cassinidev.codeplex.com/ It has many advantages for example

  • No need IIS 7 on client machine
  • Support MVC (I have tested myself)
  • Work well with Windows Form and Web Browser Control for packaging as Windows App
  • Cross Win OS platform ( Windows XP, Vista, 7) I have test XP with .NET 4 installed

Hope this helps.

embarus
  • 815
  • 3
  • 14
  • 28
  • 1
    It can run in the user process, or you can run it with its own hosting process using command line arguments. To run it in your own process, all you need is to reference the .NET assembly and call functions to start or stop the server (which runs on its own thread). – Trevor Elliott Aug 15 '13 at 16:32
4

I know this question is old, but it is still relevant, so with the .NET Core 1.0 + ASP.NET MVC 6 you can self-host your MVC application easily. You can even combine MVC and WebAPI applications into one, and you can decide later if you want to use IIS, IIS Express or the self-hosting feature of the .NET Core.

You can try it if you follow the Yeoman approach from this post: https://stackoverflow.com/a/30314393/980247

Community
  • 1
  • 1
Andras
  • 430
  • 7
  • 9
  • ASP.NET Core MVC != ASP.NET MVC. There isn't "ASP.NET MVC 6" either (because its official name is ASP.NET Core MVC 1.0). It is not a good idea to put such an answer here for the question. – Lex Li Sep 01 '21 at 00:30
  • As you can see there was a name convention shift in 2016-2017: https://www.c-sharpcorner.com/article/basics-and-over-view-of-asp-net-mvc-6-in-visual-studio-2017/ It would be great to have a more up-to-date answer for sure, so please add a new answer with the current versions if you feel like it. – Andras Sep 02 '21 at 21:23