core mvc hosted in IIS virtual directory okta sign-in redirect not working

Hey, I am testing okta with core mvc, target framework .net 6.0. The sample works fine when running local on iisexpress or kertrel webserver.
Example: running locally the application url is https localhost:7173. The Sign-in redirect URIs in okta is https://localhost:7173/authorization-code/callback. This works fine.
But If I publish this project and put it in IIS in a virtual directory called testokta. The application url will be http://localhost/testokta/ okta redirect doesn’t work. I have the Sign-in redirect Uri in okta set to http://localhost/testokta/authorization-code/callback. After Authenticating when it tries to get to Sign-in redirect Uri I get 404. I have tried to set the callback option in AddOpenIdConnect as below but no success
oidcOptions.CallbackPath = builder.Configuration[“Okta:CallBackPath”];
I tried to set redirectUri that too no success
oidcOptions.Events = new OpenIdConnectEvents
OnRedirectToIdentityProvider = context =>
context.ProtocolMessage.RedirectUri = builder.Configuration[“Okta:CallBackPath”];
return Task.FromResult(0);
My Question is, how do set the callback uri in core mvc when the application is hosted in IIS in a virtual directory. All the example I see are running iisexpress with a portnumber not sitting behind the IIS virtual directory.

Hi @rrokta,

Does it work if you add the port number like http://localhost:/testokta/authorization-code/callback.

Here is a blog post that could help you:

1 Like

No adding the portnumber doesn’t work.

Hi @rrokta,

Do you see any error in your system logs in Okta when you are redirected to your virtual path?

An unhandled exception has occurred while executing the request.

System.Exception: An error was encountered while handling the remote login.
—> System.Exception: Correlation failed.
— End of inner exception stack trace —
at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler`1.HandleRequestAsync()
at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.g__Awaited|6_0(ExceptionHandlerMiddleware middleware, HttpContext context, Task task)