We help IT Professionals succeed at work.

Self Hosting a dotnet core 2.1 api as a application instead of using IIS.

131 Views
Last Modified: 2020-04-06
I have built a simple api in dotnet core 2.1, using the following example:  ("https://www.codingame.com/playgrounds/35462/creating-web-api-in-asp-net-core-2-0/part-1---web-api")

I am in the process of trying to build and host this api on my local machine. I have published it, created a new website in IIS, with an application pool, coppied the files over, etc. When I try to run it locally on my chrome, I get "This page isn’t working 192.168.1.110 is currently unable to handle this request.
HTTP ERROR 500"

I tried following this guide: "https://www.c-sharpcorner.com/article/publish-asp-net-core-2-0-application-on-iis/" but to no help.

When I run this example in visual studio, it works fine. Am I missing something in the publishing steps or config file that is causing this to happen?


As a side note, I have also installed the .net core hosting package, etc.
Comment
Watch Question

Chinmay PatelChief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Hi,

Share the web.config from your published folder please. Remove any sensitive information from that file before posting it here.

Regards,
Chinmay.

Author

Commented:
I hope this is the file you are looking for. (its small enough to just copy and paste the contents)   web.config from my published file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\API.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
    </system.webServer>
  </location>
</configuration>
Chinmay PatelChief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Yeah that's the one. Please use Code tags from the toolbar to publish your code, it makes it easily readable.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\API.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

Once you replace the web.config as per the above one, check your logs folder (you will have to manually created it in your web apps' root. logs and then a child folder stdout). If you have configured everything properly, you will start seeing entries in stdout folder. It might give you the real error why it is not running OR it will simply start working.

Author

Commented:
After a lot of struggling I found that the configuration was not correct in my Startup.cs file.  Without the env.IsProduction() option, when building and deploying it to iis, it simply was not configured to work on a released version.


While reading up about this,  I have seen that it is possible to self host an API,  instead of hosting it in IIS, but rather as a application (which seems to be very possible with .net core). This would be the true answer to my question, although I am still looking as to how to configure and build it to self host.

I am changing the title of the Question to hopefully ask a more spesific question about self hosting.

Regards.
Chief Technology Ninja
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
I will do that.  Thank you very much.

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.