Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying ASP.NET Core 2.1 React App on IIS server

I am trying to host a default React Application over my local IIS system.

Configurations are as follows

  • Visual studio 2017
  • IIS 10
  • 64 bit operating system
  • ASP.NET CORE 2.1

I've installed pre-requisites i.e. asp.net core 2.1 hosting bundle and runtime.

When I published application its directory are as follows

enter image description here

And hosting configuration I made:

  • created a new application pool with No managed code
  • Used this pool to host the web site

But when I run the application on browser it is showing 404 error, It is not finding the application.

However, with ASP.NET CORE 2.0 it is working with the same configurations.

Is this ASP.NET CORE 2.1 removed support for such applications ?

I've been through all possible forums and none of them mentioned how to host 2.1 application with React-Redux template.

Please help

like image 786
user10005648 Avatar asked Jul 03 '18 07:07

user10005648


3 Answers

I think I found the problem. It is something https enable configuration comes with default project of ASP.NET CORE 2.1.

When I hosted it on IIS server it was redirecting it to https url but IIS was not configured for IIS protocol.

For my needs I removed HTTPS redirection from Configure Method of StartUp.cs file

Removed app.UseHttpsRedirection()

It was now redirecting to HTTP

like image 196
user10005648 Avatar answered Sep 21 '22 15:09

user10005648


I had a similar issue and it had something to do with publishing both projects at the same time. This is what worked for me:

  1. Publish ASP.Net Core app to a local folder
  2. Delete the build folder in ClientApp
  3. Zip the published folder and copy it to where you want on your IIS Server
  4. Unzip the project on the server
  5. run the command npm run build from inside the Client App folder

PS Make sure the project is marked as an application in IIS Enable Directory Browsing for that project if need Make sure you set homepage in your package.json if it's not in the root directory of your IIS Server

like image 23
srian Avatar answered Sep 21 '22 15:09

srian


This worked for me.

  1. Its a 2008 Windows Server - not ideal but set application pool to unmanaged code
  2. I Have React 16.8 inside the 2.2 application.
  3. switch to Release build with Production setting - Publish
  4. Change package.json to have homepage pointing at proper location
  5. Add a web.config file to the ClientApp/build folder for the rewrite module

The web.config that is in the build folder looks like this

<configuration>
<system.webServer>
<rewrite>
    <rules>
    <rule name="React Routes" stopProcessing="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
        <action type="Rewrite" url="/dynamotoolsapi" />
    </rule>
    </rules>
</rewrite>
</system.webServer>
</configuration>

/dynamotoolsapi happens to be the directory where my entire .net solution is , thus change your accordingly.

NO you don't need or want to delete the build folder and have to do that on the server.

like image 21
Tom Stickel Avatar answered Sep 21 '22 15:09

Tom Stickel