Custom IHttpHandler 404 not found in .NET Framework 4.7.2

 

When you add a custom IHttpHandler to your ASP .NET Framework 4.7.2 project in a root folder like /Handlers/MyHandler.ashx and you access the url /Handlers/MyHandler.ashx, this handler will be executed,

But if you want this handler to be executed on another path, you will have to register the custom IHttpHandler.

 

In my case on IIS 10 with application pool in integrated mode (Managed Pipeline Mode = Integrated):

<system.webServer>
  ...
  <handlers>
    ...
    <add name="DownloadFile" verb="*" path="Helpers/DownloadFile.ashx" type="My.Custom.NameSpace.MyHandler, My.Assembly " resourceType="Unspecified" />
  </handlers>
</system.webServer>

 

But if you are also using MVC routing, you will have to ignore this route in the MVC routing:

 

public static void RegisterRoutes(RouteCollection routes)
{
            routes.IgnoreRoute("Handlers/MyHandler.ashx");

 

 

 

Solution

https://stackoverflow.com/questions/2858738/problem-mapping-httphandler-http-error-404-not-found/5247330

 

Fix .NET 4.7.3 MVC PowerShell msbuild csproj – ASPNETCOMPILER : error ASPRUNTIME: ‘/temp’ is not a valid IIS application.

 

 

On a specific system, when using msbuild in the folder: “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin”, I was getting the error:

….csproj” (Build target) (1) ->

   (MvcBuildViews target) -&gt;


     ASPNETCOMPILER : error ASPRUNTIME: '/temp' is not a valid IIS application. [C:\Dev\pri\ZvdZOnline\Source\ZvdZOnline\Zv 


   dZOnline.Web\ZvdZOnline.Web.csproj]

 

But when I build the project by using msbuild found in “C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin” the error was resolved.

 

To resolve the error with the msbuild found in “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin”, I replaced the folder by one found on an other system, that did not have the error.

.NET 4.7.3 How to fix: The CodeDom provider type “Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” could not be located.

 

Solution

  • Close Visual Studio 2019
  • Remove package.lock.json
  • Execute: npm i
  • Open Visual Studio 2019
  • Rebuild project

 

 

 

Error

The CodeDom provider type “Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” could not be located.

File: …\ASPNETCOMPILER

PowerShell – Negate boolean – use -Not

 

https://stackoverflow.com/questions/8095638/how-do-i-negate-a-condition-in-powershell

 

 

function FolderExists {

    param($folder)

 

    $folderExists = Test-Path “$($folder)”

    If ($folderExists -eq $True) {

        Write-Host “Folder [$($folder)] exists.”

    } Else {

        Write-Host “Folder [$($folder)] does NOT exist.”

    }

    return $folderExists

}

 

if(-Not (FolderExists -folder “C:\ThisFolderDoesNotExistOnThisSystem”)) {

    Write-Host “Folder does not exists!!!!!”

<

p style=”background: #1e1e1e”>}

 

 

 

 

NET 5.0 – Windows Server 2008 R2 Standard – Unable to load ‘D:\Websites\VBV\.\hostfxr.dll’. This might be caused by a bitness mismatch between IIS application pool and published application.

 

Solution

By default the application was created with “Enable 32-Bit Applications” set to true.

After changing this to “false”, the error was resolved.

 

 

Error

Failed to start application ‘/LM/W3SVC/3/ROOT’, ErrorCode ‘0x800700c1’.

Could not find ‘aspnetcorev2_inprocess.dll’. Exception message:

Unable to load ‘D:\Websites\VBV.\hostfxr.dll’. This might be caused by a bitness mismatch between IIS application pool and published application.

 

 


 

.NET 2.2 => NET 5.0 – Endpoint Routing does not support ‘IApplicationBuilder.UseMvc(…)

 

Solution

 

Use “endpoint” routing

Old

app.ConfigureExceptionHandler(loggerFactory);

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseSpaStaticFiles();

app.UseAuthentication();

app.UseCors(“CorsPolicy”);

app.UseMvc(routes =>

{

routes.MapRoute(

name: “default”,

template: “{controller}/{action=Index}/{id?}”);

});

 

New

 

app.ConfigureExceptionHandler(loggerFactory);

app.UseHttpsRedirection();

app.UseStaticFiles();

app.UseSpaStaticFiles();

app.UseRouting();

app.UseCors(“CorsPolicy”);

app.UseAuthentication();

app.UseEndpoints(endpoints => {

endpoints.MapControllerRoute(

name: “default”,

pattern: “{controller}/{action=Index}/{id?}”);

});

 

 

 

Error

System.InvalidOperationException

HResult=0x80131509

Message=Endpoint Routing does not support ‘IApplicationBuilder.UseMvc(…)’. To use ‘IApplicationBuilder.UseMvc’ set ‘MvcOptions.EnableEndpointRouting = false’ inside ‘ConfigureServices(…).

Source=Microsoft.AspNetCore.Mvc.Core

StackTrace:

at Microsoft.AspNetCore.Builder.MvcApplicationBuilderExtensions.UseMvc(IApplicationBuilder app, Action`1 configureRoutes)

at BestandenDelen.Web.Startup.Configure(IApplicationBuilder app, IConfiguration configuration, IDatabaseService databaseService, IEnvironmentService environmentService, ILoggerFactory loggerFactory) in C:\Dev\bestanden-delen\BestandenDelen.Web\Startup.cs:line 157

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)

at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)

at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)

at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)

at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)

at Microsoft.AspNetCore.Server.IIS.Core.IISServerSetupFilter.<>c__DisplayClass2_0.<Configure>b__0(IApplicationBuilder app)

at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)

at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__31.MoveNext()

.NET 2.2 => NET 5 – Fix – The call is ambiguous between the following methods or properties: ‘ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Assembly[])’ and ‘ServiceCollectionExtensions.AddAutoMapper(IServiceCollection, params Type[])’

 

To fix this error I followed: https://www.thecodebuzz.com/configure-automapper-asp-net-core-profile-map-object/

 

services.AddAutoMapper(typeof(Startup).Assembly);

NET 5 – Fix – System.InvalidOperationException: ‘Application is running inside IIS process but is not configured to use IIS server.’

 

After updating a .NET Core 2.2 app to NET 5, the following error appeared:

System.InvalidOperationException: ‘Application is running inside IIS process but is not configured to use IIS server.’

 

To fix this use HotBuilder instead of WebHostBuilder

 

public class Program

{


    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));

 

    public static void Main(string[] args)


    {


        CreateHostBuilder(args).Build().Run();


    }

 

    public static IHostBuilder CreateHostBuilder(string[] args) =&gt;


        Host.CreateDefaultBuilder(args)


            .ConfigureWebHostDefaults(webBuilder =&gt;


            {


                webBuilder


                .UseKestrel(serverOptions =&gt; serverOptions.AddServerHeader = false)


                .UseIISIntegration()


                .UseStartup&lt;Startup&gt;();


            });


}

 

NET 5 – Fix – ‘IConfigurationSection’ does not contain a definition for ‘Get’ and no accessible extension method ‘Get’ accepting a first argument of type ‘IConfigurationSection’ could be found (are you missing a using directive or an assembly reference?)

 

‘IConfigurationSection’ does not contain a definition for ‘Get’ and no accessible extension method ‘Get’ accepting a first argument of type ‘IConfigurationSection’ could be found (are you missing a using directive or an assembly reference?)

 

https://stackoverflow.com/questions/45039136/bind-an-iconfigurationsection-to-a-complex-object-without-asp-net-core

 

Install the package