Publish dotnet core application to IIS

From Logic Wiki
Jump to: navigation, search


Prerequisites in IIS server

if you see 502.5 error this is the solution

  • If you see 500.19 error install HTTP Platform Handler

Creating Site in IIS

  • Sample screenshot of an imaginary site called MySite is below

IIS1.png

  • Go To Application Pool and change bindings like below (No Managed Code)

IIS2.png

  • Go to Advanced settings in application pool and click Identity. Change it to Network Service (it may not be necessary but if you have problem with reading web.config file this is one of the solutions)

IIS3.png Here is a sample web.config file. It must be produced during publish but in some cases API projects don’t produce it. In the absence of web.confg, site returns 404. If your publish doesn’t have this file, change the red text below with relevant dll name and use it in deployment

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\TestApp.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>
<!--ProjectGuid: f0ce46ec-ecbc-4c85-ade9-6210a3e1e8b9-->

HOW TO ADD A CORS COMPLIANT HTTP RESPONSE HEADER TO IIS

In our case we will add the ‘Access-Control-Allow-Origin’ HTTP Response header.

  1. On the Windows server select the Internet Information Services (IIS) Manager application from the icons in the bottom bar or click the Windows icon and select “Server Manager”
  2. Navigate to the website you need to edit the response headers for.
  3. From the list or Icons related to the site you are editing, select “HTTP Response Headers”.
  4. After it opens look for “HTTP Response Headers”. It will say say, “Use this feature to configure HTTP headers that are added to the responses from the Web server.”
  5. Click “Add”
  6. A dialog box will open. For name enter “Access-Control-Allow-Origin” and for Value enter an asterisk. Or, if want to restrict the interactions to queries from a particular site, then enter that domain.

Then click the OK button.