0

I have a ASP.NET Web-API which has a IHostedService to periodically execute a specific Task (fetch data from another website and write it to the Database).

This works well on IIS-Express (starting from inside VisualStudio)

But when publishing the API to either my local IIS or the IIS of my external provider, the IHostedService doesn't start.

in my startup.cs: services.AddHostedService<QuartzHostedService>();

I tried adding values to the Database manually when calling a specific Path, so that's not the problem. It has something to do with IIS i guess. Problem is, I don't have access to the external providers IIS configuration. Everything i found online showed some IIS configuration.. I hope someone can help.

  • Could you please check the IIS process has started or not? You could check inside the task manager to find if the w3wp.exe has started or not. – Brando Zhang Feb 24 '22 at 13:39
  • What you did is not recommended and can fail in many cases, https://blog.lextudio.com/unpleasant-facts-about-hangfire-632a3228ff8a So when you "don't have access to the external providers IIS configuration", you will have to use other approaches instead, not within a web app. – Lex Li Feb 24 '22 at 15:27
  • @BrandoZhang @Lex Li so it turns out, that what was mentioned in your article @Lex Li absolutely matches my problem. I try solving it by using a Linux root server now for hosting the `ASP.NET` app. If that doesn't work, I go for a Windows root server :D But I think linux should do the work. Thanks for your Help. – totallynotatallno Feb 26 '22 at 11:39

1 Answers1

0

Steps to setup on IIS

  1. Adding "Application Initialization" feature, only available since IIS 8.0 and hier.
  • First do you need to enable on server the feature "Application Initialization", so, on "Server Management" --> "Management" --> "Add roles" --> "IIS Web Server" --> "web Server" --> "Application Development" --> "Application Initialization"

enter image description here

  1. Create your Application Pool
  • Set properties:
    • starter mode: AlwaysRunning
    • .NET CLR: V4.0 (even if your project is .net core,beacuase the configuration donesn't work fine if you change that)
    • Idle: 0
  1. Create your Application under your IIS Site and configure advanced settings:

    • ApplicationPool: with the pool created on previous step
    • Preload active: True
  2. Start yoour Pool or recycle and your hosted service must run,

IMPORTANT: Exists an issue, https://learn.microsoft.com/en-US/troubleshoot/developer/webapps/aspnet/site-behavior-performance/application-fail-ssl-web So if your site has enabled "SSL Required" do you need to change that from your particular site,

  • On iis select your application and on Middle planel "IIS" section double click on "SSL Configuration"
  • Then uncheck "SSL Required"

enter image description here

Your Hosted Service