self hosting asp.net mvc
Asked Answered
P

3

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?

Pingpingpong answered 30/4, 2012 at 5:38 Comment(0)
S
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
Sinciput answered 30/4, 2012 at 5:53 Comment(2)
very nice! Will mark as answer if no one else has nothing more to addPingpingpong
This looked good, until I read that the computer running the code must have IIS7 installed, even though your code is hosted in your own process.Randallrandan
D
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.

Dichogamy answered 11/10, 2012 at 8:20 Comment(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).Hydrangea
M
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://mcmap.net/q/321254/-is-it-possible-to-self-host-an-asp-net-core-application-without-iis

Merely answered 14/12, 2016 at 11:17 Comment(2)
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.Recurrent
As you can see there was a name convention shift in 2016-2017: c-sharpcorner.com/article/… 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.Merely

© 2022 - 2024 — McMap. All rights reserved.