Hosting OWIN as a Web Application in IIS 7 (OWIN Startup is not invoked inside a virtual directory)

I have an Owin middleware authentication project deployed as a web application in IIS 7.5 but the problem is that Startup.cs is not getting called.

[assembly: OwinStartup(typeof(Authorization.Startup))]

namespace Authorization
{
    public partial class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            //Logger.Write(string.Format("Authorizations->frist Configuration "), LoggingCategoryNames.PRESENTATION_LAYER_LOGGING_CATEGORY);
            ConfigureAuth(app);
        }
    }
}

      

this code fails. when we deploy it as a root level site everything works fine.

So where are we going wrong and what can be done to make it work. We cannot deploy our authentication project as a separate website, it should only be a web application.

thank

+3


source to share


1 answer


I found something similar. My method was Configuration

running, but the authentication middleware (OpenIdConnect in this case) didn't seem to run in the Owin pipeline when hosted as a child web app. It worked great when hosted as the root website.

Before diving deeper into debugging the pipeline itself, I tried a couple of things that I have seen cause problems when using other token services (ADFS for one). And of course it turned out to be one of them.

Old problem with closing forward slash.

My OpenIdConnect configuration in the client application looked like this:

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    Authority = "https://idserver/identity",
    ClientId = "Client",
    RedirectUri = "https://clients/mvcclientapp"
    ...
});

      



And the client just won't process the incoming token. Apparently the middleware was not running inside the pipeline.

I added an extra "/" to the end of the RedirectUrl and it started working.

app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
    Authority = "https://idserver/identity",
    ClientId = "Client",
    RedirectUri = "https://clients/mvcclientapp/"
    ...
});

      

This is NOT NECESSARY when hosting in IIS as the root website.

+2


source







All Articles