Run different ASP.NET Core webapps under same domain - asp.net

I'm trying to create a container (parent) web app loading other web applications inside its body.
Each web app is an ASP.Net Core project, using its own Kestrel web server. With old ASP.Net, I would use virtual directories to have them under same the same site, avoiding the concern to handle cross domain CORS, but I can't find a way to do it with asp.net core modules.
Container (localhost)
App1 (localhost/App1)
App2 (localhost/App2)
App3 (localhost/App3)
Is there a way to handle this scenario?

You need change default app name in Web.config, each new application has a different name: <add name="herenewapp" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />

Related

Dont serve requests before site is warmed up on Azure

Is it possible to have some kind of timeout to make sure site is warmed app after website is scaled out or instance was restarted in Azure?
We are hosting Sitecore website on Azure Webapp and wouldn't like any requests to be handled by instance before its warmed up and instead served by other healthy nodes.
You can use application Initialization to warmup the Azure web app. See iis-80-application-initialization
In the web.config this look like:
<web.webServer>
<applicationInitialization>
<add initializationPage="/" />
<add initializationPage="/page-2" />
</applicationInitialization>
</web.webServer>
Since it is for Sitecore see also this blog warmup-your-application-on-azure-app-service-when-scaling-up-and-swapping-slots-using-application-initialization/

.NET Core IISIntegration configuration

Pretty new to .NET Core, and am trying to understand how everything works together when using IIS integration.
A couple of questions: If I want my site to run over HTTPS, do i need to configure my WebBuilder with a certificate, or should i be selecting HTTPS on the binding in IIS manager, or both?
Does the UseUrls WebBuilder method also instruct IIS what port is should listen on? How does IIS know which port it should talk to the .NET Core application on?
When you host your .NET Core app behind IIS, IIS is acting as a reverse proxy to Kestrel web server. IIS will receive the HTTP request and pass it to Kestrel, the magic happen inside a new IIS module called AspNetCoreModule that you have to install on your server. As usual, to configure your IIS application you'll be using a web.config file in which you'll find a description of how IIS is interacting with your app: timeouts, pathes of the application, environment variables and so on... For instance, mine look like that:
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified"/>
</handlers>
<aspNetCore
requestTimeout="00:20:00"
processPath="%LAUNCHER_PATH%"
arguments="%LAUNCHER_ARGS%"
stdoutLogEnabled="false"
stdoutLogFile=".\logs\stdout"
forwardWindowsAuthToken="true">
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="development" /> <!-- value could be "development", "staging" or "production"-->
</environmentVariables>
</aspNetCore>
</system.webServer>
The reason why you want to set it up that way is that Kestrel is a very light weight and nervous web server but it's missing a layer of applicative features that IIS can add up: Windows authentication via Kerberos, restarting the app in case of a crash, pool management...
I like a lot this article regarding this topic: https://weblog.west-wind.com/posts/2016/Jun/06/Publishing-and-Running-ASPNET-Core-Applications-with-IIS
For HTTPS, it's enough to configure IIS to listen on a secure HTTPS port and to define the certificate only on IIS.
UseUrls() won't be taken into account by IIS, it will work the other way around, IIS will tell your app on which port it should be listening to, UseUrls() will be taken into account if you launch your app directly.

404 error when running custom asp.net application under CRM 2016 web directory

I am trying to get a custom web application working under CRM's web directory i.e. C:\Program Files\Microsoft Dynamics CRM\CRMWeb\ on a new server with CRM 2016. The same setup was working fine on a CRM 2013 server, from which we are trying to upgrade.
The path is correct because when I remove any of the DLLs from my custom app, I get correct ASP.net error about the missing DLL. But as soon as all DLLs are correct, I get a 404 error for my custom web application.
I know it's not a good news but putting WWW app in CRM Webapp directory is not supported - you can read it here:
Creating an Internet Information Services (IIS) application inside the Microsoft Dynamics 365 website for any VDir and specifically within the ISV folder is not supported. The \ISV folder is no longer supported.
I can imagine that some httpmodule inside CRM 2016 is catching requests to your site.
Just to add to pens's comment You will need to rewrite the existing web application as standalone web application and use the CRM SDK to access crm.
https://msdn.microsoft.com/en-us/library/gg334357(v=crm.6).aspx
I had do migrate a few of these back in the CRM4 to CRM2011 days and generally it was a pretty painless experience.
The basic things to remember were:
Configure the website to use windows authentication (to allow us to identify the user of the webextension)
Look up the systemuser by domain name to get their system user id and then impersonate in the webapplication where necessary.
(https://msdn.microsoft.com/en-us/library/gg309629.aspx)
Allow Cross Site Scripting between CRM and your web site.
This allows you to interact with the iframes or rest services hosted by your webapplication using JavaScript from CRM
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://crmurl" />
<add name="Access-Control-Allow-Credentials" value="true" />
<add name="Access-Control-Allow-Headers" value="Origin, Authorization" />
<add name="Access-Control-Allow-Methods" value="POST, GET, OPTIONS" />
<add name="Access-Control-Expose-Headers" value="WWW-Authenticate" />
</customHeaders>
</httpProtocol>

Aurelia does not load on azure, due to HttpPlatformHandler?

I'm using ASP.NET Core RC1 as server to host my Aurelia app. My app was working just fine but the last couple of weeks something changed so that the app does no longer load when hosted on Azure. I'm not sure if it is something I changed or if it's a change on the Azure side but I'm leaning towards the latter.
I've narrowed down the problem quite a bit. The app runs fine locally, with ASP.NET Core Kestrel server and also other servers (e.g. webpack-dev-server). I have continuous deployment setup from Visual Studio Team Services to an Azure Website. The app is published and a web.config is automatically created in my wwwroot:
<configuration>
<system.webServer>
<handlers>
<add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%home%\site\approot\web.cmd" arguments="" stdoutLogEnabled="true" stdoutLogFile="\\?\%home%\LogFiles\stdout.log"></httpPlatform>
</system.webServer>
</configuration>
Nothing happens when I navigate to my site, e.g. http://demo.azurewebsites.net/. When looking at the console I get a 404. Once I actually got this error but I can't seem to bring it back: 502 - Web server received an invalid response while acting as a gateway or proxy server
I have index.html set as default document but it is not loading. If I enter it explicitly, the app works: http://demo.azurewebsites.net/index.html
If I remove the httpplatformhandler from the web.config, then it works as expected (index.html is loaded automatically). The same happens when I remove the web.config entirely. In these cases the MVC 6 WebAPI behind the scenes does not work at all. I assume that's just logical since I remove the platform handler.
So, why is this httpplatformhandler added? Is it necessary? Why is it created? Is there some setting in the Azure portal that I can adjust to prevent this handler to be configured like this?
I also found this link that seems to suggest that things are changing and that this httpplatformhandler is about to be replaced: Closer Look: Hosting ASP.NET Core on Azure App Service
I'm out on deep water here and any and all help is appreciated.
To get default document support with the static file server middleware you need to use app.UseFileServer() instead of app.UseStaticFiles()

Allow only one web app to call a web service

How to configure that a web service only be called by one specific web application? Both ones are in the same IIS server.
Framework: 2.0
I think that setting web.config of web service would be enough.
On this example, I'm setting web.config of web service. Web service will be called only by one IP address (127.0.0.1 is IP of IIS Server):
<location path="resources">
<system.webServer>
<security>
<ipSecurity allowUnlisted="false">
<clear/>
<add ipAddress="127.0.0.1"/>
</ipSecurity>
</security>
</system.webServer>
</location>
Would it be ok?
If it's only being called by one specific application on the same server, a Web Service may not be the right choice. It would make more sense for the code to be within a class in the same app. Web services are best suited for situations where multiple apps need to access the same functions.
That said, with IPV6 coming, the option you thought of won't work. If you're really just trying to limit requests to apps that come from the same sever, in you can put the following in code to check to see if it's coming from the local server:
if(Request.IsLocal)
{
//code here
}
For simplicity's sake, you can put the following in Application_BeginRequest in the global.asax file for the web services:
if(!Request.IsLocal)
{
throw new Exception("Only local requests are allowed");
}
This will effectively fend off anything not coming from localhost.

Resources