IIS : Host a .net Core application under .net framework Website - asp.net-core

Hosting ASPNETCore sub-application under ASPNET .netframework website.
I have a website hosted under IIS which is developed in ASP.NET MVC 4 targeting to .NET Framework 4.0
and i'm trying to add an application developed with ASPNET Core under this website.
are we able to do that ?
(I tried, and its work only if i host them separately in two websites)

There's not enough here to help you, specifically, but generally speaking, this is problematic because ASP.NET Core only uses Web.config to load the ASP.NET Core hosting IIS module, and an ASP.NET site is going to have all sorts of things in its Web.config, including many conflicting HTTP modules.
Web.config is inherited by default. While you can turn off individual sections with inheritInChildApplications="false". You must add this to every, single section in the parent's Web.config, and remember to do any time you add new sections in the future, or it will break you ASP.NET Core app. If you have to, then you have to, but the idea that a change to some other application will potentially break another without any indication that a problem has occurred is a scary prospect to say the least.
It would be far better to just host the ASP.NET Core on a subdomain or something, and let it be its own site.

Related

Can a Worker Service be called and/or used inside an existing ASPNET.Core web project?

I've been reading and learing about the new Worker Service features provided in .Net Core 3.0. I have been using this link from Microsoft: Background tasks with hosted services in ASP.NET Core
What I don't understand is this, can these worker service concepts be introduced into an existing ASPNET Web Project, like a Razor Pages site? Or must you create a new project and then deploy that project as a service using whatever mechanism the host OS proivdes for that?
Yes, you can host any number of hosted services (IHostedService) within ASP.NET Core applications. With version 3, ASP.NET Core uses the generic host (Host.CreateDefaultBuilder) which is the framework that is hosting these hosted services when the application starts. In fact, the ASP.NET Core web application is an IHostedService itself.
To add additional hosted services to your ASP.NET Core application, just register additional hosted services with your service collection, e.g. within the Startup’s ConfigureServices:
services.AddHostedService<MyHostedService>();
That service will then launch together with the ASP.NET Core web server when the application runs.
The Worker SDK that is mentioned in the documentation is actually a subset of the Web SDK that you are using with ASP.NET Core application. Microsoft.NET.Sdk.Worker is basically Microsoft.NET.Sdk.Web without the web-specific stuff like Razor compilation and wwwroot folder stuff. It basically sets up automatic file globbing e.g. for the appsettings.json and does some other useful things that the core Microsoft.NET.Sdk does not have.
Ultimately this means, that when you are using the Web SDK, then you already have everything the Worker SDK offers. So you do not need to specify the Worker SDK just to host additional background services.

Running ASP.NET Core within/alongside an existing ASP.NET WebForms project in Visual Studio and IIS Express

I have a large Visual Studio solution with several ASP.NET web sites with a mix of WebForms, MVC and WebAPI. What I'd like to be able to do is add an ASP.NET Core project to this solution to provide MVC, Razor Pages, WebAPI and SPA (Vue.JS in this case) facilities. The plan is to take each WebForms page at a time and convert to the new framework.
I'll target .NET Framework and the Core site will share some assemblies from the WebForms - but no state is shared except a session cookie and any state stored in the database.
I specifically want to be able to serve the new framework from IIS Express on the same port. So for example, an old page such as http://localhost:1234/page1.aspx will be converted to http://localhost:1234/core/page1. However, I'm unable to simply change the Core project to be hosted on IIS Express and change the path to http://localhost:1234/core. I have managed by following instructions to host in IIS but this has several disadvantages for development. I've also tried adding <urlRewrite> configuration to the WebForms site to forward requests to Core running on a different port but I wasn't very successful and I believe POST request are not supported which renders it fairly useless!

.NET Core Hosting Bundle

As far as I understood the Docs, the .NET Core Hosting Bundle installs the .NET Core Runtime, .NET Core Library and the ASP.NET Core Module.
It seems that there's a Bundle for every version of the .NET Core Runtime (2.0.6, 2.0.7, ...).
If I have a self contained deployment of my app, I still need the ASP.NET Core Module. However I don't see that the Module can be downloaded separately without the full bundle. Is there a place where I can download it ?
If not:
What's the point of having a self contained application, if I still need to install the whole .net core sdk/runtime bundle on my IIS Server?
There is no official download of the ASP.NET Core Module for IIS ("ANCM"), though it can be installed by calling the hosting bundle installer with OPT_INSTALL_LTS_REDIST=0 OPT_INSTALL_FTS_REDIST=0 as arguments (at least for 1.0-2.0 installs).
What's the point of having a self contained application, if I still
need to install the whole .net core sdk/runtime bundle on my IIS
Server?
Apart from the installer being able to install only ANCM, do not forget that IIS is not the only hosting option for ASP.NET Core Applications. People may still opt to host it on linux or as a Windows Service. Either being exposed to the public Internet (which is supported from 2.0+) or behind NGINX/Apache/…
It is also very useful to deploy preview, daily or custom builds of any component inside .NET Core / ASP.NET Core if needed.
Check the docs on this topic.
The ASP.NET Core Module is a fork of HttpPlatformHandler which was modified to work with ASP.NET Core's new system and was previously used to host ASP.NET Applications. related GitHub issue
IIS needs it in order to start up your ASP.NET Core application when the first request arrives and to route requests to the ASP.NET Core application.
With .NET Core (and hence ASP.NET Core), ASP.NET Core comes with its own http server (previously this was only possible with Http.sys aka WebListener self-hosting, i.e. commonly used for WCF services). It also redirects a couple of headers to the application, since IIS with ASP.NET Core only acts as reverse proxy.
In other words, ASP.NET Core is hosted outside the IIS process, and ASP.NET Core Module is there to communicate with it and starts the outside process if not already. This also means, that ASP.NET Core applications hosted in IIS are subject to IIS lifetime cycle (i.e. IIS may and will stop your applications when idle - This doesn't happen when you self-host your application or use something like nginx as reverse proxy).
With ASP.NET Core 2.1 preview1 it will also be possible to host ASP.NET Core application in the IIS process (w3wp.exe) for a improve request throughput. For more information on this, read ASP.NET Core 2.1.0-preview1: Improvements to IIS hosting

ASP.NET Core Application Initialization on Azure

I'm trying to implement Application Initialization (warm up) on an ASP.NET Core web app running on Azure, as described for IIS 8.
The way it's described is changing web.confg to enable and configure it.
But in asp.net core we (almost) don't have web.config.
So, how do we configure Application Initialization (or any other feature that require
changing web.config)?
I finally figured out, for this question and any other that requires IIS to be configured through web.config:
It's not true there isn't web.config anymore. It's true that it doesn't play any role in the asp.net core app, but you can find a small web.config file in wwwroot project folder, which is what tells IIS how to handle the asp.net core app.
So for implementing this, or for example urlrewrite, you just need to add IIS configuration to that web.config file as it's being deployed as part of the application.

Netduino or Gadgeteer running IIS and ASP.NET MVC

Is it possible to deploy ASP.NET MVC3 applications onto either a Netduino or .NetGadgeteer? If so how would I go about such a thing?
What I want to do is have a Netduino, connected to a wifi router, that will host an MVC web app.
No, it will not support it. In order to run ASP.Net, you need to have some kind of IIS running. It is quite simple to serve HTML on HTTP on .Net Micro framework, but in order to use ASP, you need either a full fledged IIS server or some kind of embedded ASP server, like the one in Visual Studio (Cassini was the code name, I think).
You basically 4 choices:
Find an embedded ASP server. There is a .net project called aspnetserve that can serve ASP pages, you may be able to port is to the Micro Framework.
Step up to Windows CE, which can host ASP .Net pages.
Serve plain HTML pages that you build on the spot.
Use a templating engine other than ASP and port it to .Net MF if needed
Both Gadgeteer and Netduino run the .Net Micro Framework which will not support an ASP.NET MVC web application.
People have implemented simple web servers inside Netduino.
Do you really need to host the MVC website on your Netduino or do you have a computer/device available to host the website and simply have your controllers communicate directly with the Netduino?
There's a great article on doing exactly this at http://www.codeproject.com/Articles/344471/Using-jQuery-Mobile-with-MVC-and-Netduino-for-Home