I think what you're asking for is not directly possible, but you could get close. I'm not going to offer any code here, as this could get complex, however I hope it helps you think about the problem. I agree with @jeremy-lakeman that this is an "anti-feature" that you're looking for, and maybe you can reframe the problem.
Windows Authentication
Windows will automatically authenticate via kerberos when the server sends back a 401. This is transparent to the user, and there is no login page. In your case, this is handled by IIS. At no point when using Windows Authentication should you be showing a login page.
Cookie Authentication
Essentially this is storing a cookie on the browser that is used to authenticate the user. Asp.Net Core 3.1 includes this natively, and can easily support this. The cookie is authenticated at the application level. This cookie can have an expiration, and you have a login form embedded in the page. When you create a new project, this is the "Individual Accounts" option.
Hybrid of the two
Imagine a world as follows:
You have two applications. Your primary app is configured with Cookie Authentication (we'll call it "Primary"), and a secondary app is configured to use Windows Authentication (called "Secondary"). You could also conceivably do this with IIS and put Windows Authentication for one particular path, but its easier to think about it as two separate apps.
When you make a request to Primary, your app validates the cookie. If no cookie exists, or its rejected (because the timeout hit) you are redirected (not a 401 Unauthorized, a 302 Found) to Secondary, which all it does is Windows auth. It could regenerate the cookie, and then send you back to Primary.
However this does not show you a login page, and I think that is the crux of the issue here. You want to have both automatic login, and manual login in the same application. If you have automatic login, what good is an expiration? They'll just refresh and get authenticated again.
If you ditch the idea of automatic login (via Windows Authentication) you can use only one application with Cookie Authentication.
Cookie only
In this scenario, you only have Primary setup, and it only does cookie authentication. You can have an Identity Provider that authenticates against Active Directory. This is Windows Auth, but on the application level, instead of at the IIS level.
You're going to have to choose between Automatic Logins, or Timeouts. There is no reasonable world where you can have both.
fetch
) in the page or service-worker to send requests every few minutes to keep the user's authentication token alive - but I'll admit I'm unsure how this works with Kerberos/NTML. – Dai