ASP.NET appSettings Element

Use aspnet:UseHostHeaderForRequestUrl instead of custom MVC route handler

Get original url without non-standard port (C#) - Stack Overflow

A more desirable solution for many ASP.NET applications may be to set the aspnet:UseHostHeaderForRequestUrl appSetting to true.

<?xml version="1.0" encoding="utf-8"?>
For more information on how to configure your ASP.NET application, please visit
<add key="aspnet:UseHostHeaderForRequestUrl" value="true" />
<add key="webpages:Version" value="" />
<add key="webpages:Enabled" value="false" />
<add key="PreserveLoginUrl" value="true" />
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

A quick note about ASP.NET MVC Url Helpers

If you’re using some of the Url Helpers in mvc, like Url.Action in one of your controllers, you may run into an issue where the generated url will contain a non public port number. In that case, you can just add a setting to your config value as noted here:

Setting aspnet:UseHostHeaderForRequestUrl 

to true should remedy the issue.

It should look something like this:



<add key=”aspnet:UseHostHeaderForRequestUrl” value=”true”/>

ASP.NET Core 3.0 + Web API + MongoDB

.Net Core Web Api – Basic Authentication (Source Code)


Source code from Microsoft