0

I have an application on IIS that I want to auto start. I followed the steps here and it worked! https://www.taithienbo.com/how-to-auto-start-and-keep-an-asp-net-core-web-application-and-keep-it-running-on-iis/

But this was when authentication mode in IIS was set to Anonymous Authentication. I then wanted to add Windows Authentication to my app and I was able to do so successfully. Except, the auto start of my site no longer works. Can you have your IIS app auto start with Windows Authentication mode? If so, how?

Nathan
  • 675
  • 2
  • 9
  • 20
  • Did you disable Anonymous Authentication when you enabled Windows Authentication? If not, please disable it. – samwu Aug 27 '21 at 06:18
  • Yes I did. That application does prompt for Windows Authentication just fine. However, as mentioned above, I want this application to auto start with manual intervention. But because Windows Authentication is turned on it no longer auto starts. – Nathan Aug 30 '21 at 11:15
  • I am not sure if this is still the latest on this issue but it looks like you cannot use application initialization with needing authentication. Not sure if anyone can confirm this is still the case with IIS 10.0 https://forums.iis.net/t/1220721.aspx?Application+Initialization+Autostart+Warmup+with+Windows+Authentication+fails – Nathan Aug 30 '21 at 11:59
  • yes, according to my search, it's impossible to auto start application with Windows Authentication. – samwu Aug 31 '21 at 06:07

1 Answers1

0

For those who is searching the answer - I had the same issue and my solution was:

  1. Enable anonymous globally in web.config

    <system.webServer>
      <security>
        <authentication>
            <windowsAuthentication enabled="true" />                
            <anonymousAuthentication enabled="true"/>
        </authentication>
      </security>
    </system.webServer>
    
  2. Add a default controller with empty Route and AllowAnonymous attribute

    [Route("")]
    [ApiController]
    [AllowAnonymous]
    public class DefaultController : ControllerBase
    {
        private readonly ILogger _logger;
    
        public DefaultController(ILogger logger)
        {
            _logger = logger;
        }
    
        [HttpGet]
        public ContentResult Get()
        {
            _logger.LogTrace("Warmup called");
    
            return Content("This is my webapi. see <a href='swagger/index.html'>here</a>",
            "text/html; charset=utf-8");
        }                
    }
    
  3. For those controllers that needs authentication add an Authorise attribute:

    [Route("[controller]")]
    [ApiController]
    [EnableCors]
    [Authorize]
    public class MyAuthenticatedController : ControllerBase
    {
        //...
    }
    

Also you can add a separate controller for warming up an application and specify its route in applicationInitialization web.config's section (works for IIS >= 8.0) :

<system.webServer>
  <!-- ... -->
  <applicationInitialization doAppInitAfterRestart="true" skipManagedModules="false">
    <add initializationPage="/warmup" />
  </applicationInitialization>
</system.webServer>

And finally, an answer that was helpful for me.

ka3yc
  • 116
  • 4