How to Host DNX,DNU,DotNet Core CR in IIS


Follow the steps below to host DNX/DNU based application in IIS.

1. Install URLReWrite IIS Module from this URL here

2. Install the HttpPlatformHandler v1.2 module in IIS, go to the Internet and search for it, then download it.
     - Restart IIS when it is installed
     - This handler acts as a middle man between IIS and DNX, IIS passes the traffic to the Handler, then that passes the traffic to DNX.
     - Remember DNX is the predecessor of Asp.Net Core

3. Add necessary (32 or 64-bit) DLL in either System32 is the 64-Bit Folder or SystemWOW is the 32-Bit Folder. If your application consumes dll, it will look in those two folders.

    - Unlike .Net Core which looks in the Project folder first and then moves on to System Folders to see if DLL are available, DNX or DNU looks in System folders first.

4. If your application needs andy dependency folders created, do so.
    - Create two folders and give IIS the necessary permission to access or write to those folders.

5. Make necessary changes to the application source code if needed.


About #DNX application

1. When you publish a DNX-based application, three folders are created, 
      1. approot
      2. logs
      3. wwwroot 

Mainly the URL path in the IIS will point to the wwwroot of the published folder. See below:

How to Host a DNX DNU Web Application in IIS

2. Check or verify that the httpPlatformHandler is installed in IIS. Go to the Site hosted under the Sites folder in the Connections Window of IIS. Then click on the "Modules" and look for the httpPlateformHandler.



3. Make sure that you have enabled Logging for the DNX/DNU website you are trying to host in order to see logs of errors.
   - Navigate to web.config file inside the project/website folder and set the appropriete flags for logging.

<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
    </handlers>
    <httpPlatform processPath="..\approot\web.cmd" arguments="" stdoutLogEnabled="true" stdoutLogFile="..\logs\stdout.log" startupTimeLimit="3600"></httpPlatform>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="ASP" verbosity="Verbose" />
                        <add provider="ASPNET" areas="Infrastructure,Module,Page,AppServices" verbosity="Verbose" />
                        <add provider="ISAPI Extension" verbosity="Verbose" />
                        <add provider="WWW Server" 
                         areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket,ANCM" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions statusCodes="500" />
                </add>
            </traceFailedRequests>
        </tracing> 

 </system.webServer>
</configuration>

In case of the error that says "System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters"

System.IO.FileLoadException: Could not load file or assembly 'Microsoft.Extensions.Configuration.EnvironmentVariables, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The filename or extension is too long.
File name: 'Microsoft.Extensions.Configuration.EnvironmentVariables, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' ---> System.IO.PathTooLongException: The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
   at System.IO.PathHelper.GetFullPathName()
   at System.IO.Path.LegacyNormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
   at System.IO.Path.GetFullPathInternal(String path)
   at System.Security.Util.StringExpressionSet.CanonicalizePath(String path, Boolean needFullPath)
   at System.Security.Util.StringExpressionSet.CreateListFromExpressions(String[] str, Boolean needFullPath)
   at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
   at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
   at System.Reflection.Assembly.LoadFile(String path)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadFile(String assemblyPath)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName, IAssemblyLoadContext loadContext)
   at Microsoft.Dnx.Runtime.Loader.PackageAssemblyLoader.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.LoaderContainer.Load(AssemblyName assemblyName)
   at Microsoft.Dnx.Host.DefaultLoadContext.LoadAssembly(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.AssemblyLoaderCache.GetOrAdd(AssemblyName name, Func`2 factory)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.LoadAssemblyImpl(AssemblyName assemblyName)
   at Microsoft.Dnx.Runtime.Loader.LoadContext.ResolveAssembly(Object sender, ResolveEventArgs args)
   at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
   at Microsoft.AspNet.Hosting.WebApplication.Run(Type startupType, String[] args)
   at Microsoft.AspNet.Server.Kestrel.Program.Main(String[] args)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly assembly, String[] args, IServiceProvider serviceProvider)
   at Microsoft.Dnx.ApplicationHost.Program.<>c__DisplayClass3_0.<ExecuteMain>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.Execute()

You need to shorten the path to the folder hosting DNU/DNX website. Simply, copy the wwwroot forder or output folder into a wwwroot folder for IIS restricted hosting folder. This error should now go away.


Troubleshooting
1. If you see IIS saying there is a bad module for HttpPlatform just go to the website, find Modules, then click on "Configure NativeModules
   then select httpPlatformHandler in the window that pops up.

Extra Notes
1. When you publish a DNX-based application the hosted folder can be found in the certificate folder in a Release folder. Based on how you indicated the publish path to be.





m said:

yes

Posted On: May 03, 2023 20:33:08 PM

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy