I have followed all the possible scenario to call owin startup, but still it does not work properly in IIS.
In IIS pool is integrated pipeline and setup v4.0 CLR version
In web.config
, I added the following entries:
<add key="ida:AppScopes" value="User.Read" />
<add key="owin:AutomaticAppStartup" value="true" />
<add key="owin:AppStartup" value="HR_Web.StartupTest"/>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
but it still does not get picked up as it supposed to be...
Then I tried to call this startup class through global.asax
, Application_Start
method
using (Microsoft.Owin.Hosting.WebApp.Start<StartupTest>("http://localhost:9000"))
{
ErrorHandler.Singleton().logInforDetail("Startup execution in global started", LogTypes.FileAppenderRequestLog);
}
Even though from this startup method is called when try to access context from here
Request.GetOwinContext().Authentication.Challenge(
new AuthenticationProperties { RedirectUri = "/" },
OpenIdConnectAuthenticationDefaults.AuthenticationType);
It throws this exception:
System.InvalidOperationException: 'No owin.Environment item was found in the context.'
My Global.asax as follows :
protected void Application_Start(object sender, EventArgs e)
{
try
{
log4net.Config.XmlConfigurator.Configure();
HR_BL.Assessment.AssesmentThread.AssementCalculationThread.Initialize();
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);
#endregion
using (Microsoft.Owin.Hosting.WebApp.Start<StartupTest>("http://localhost:9000"))
{
ErrorHandler.Singleton().logInforDetail("Startup execution in global started", LogTypes.FileAppenderRequestLog);
}
}
catch (Exception ex)
{
ErrorHandler.Singleton().logErrorDetail(ex);
}
}
Web.config :
<add key="ida:AppID" value="XXXX-XXXX-XXXX-XXX-c0d08bc01bc1" />
<add key="ida:AppPassword" value="XXXXXX~XXXXXXXXXX_XXXXXX" />
<add key="ida:RedirectUri" value="https://hr-esc-ut.abc/LoginMicro.aspx" />
<add key="ida:AppScopes" value="User.Read" />
<add key="owin:AutomaticAppStartup" value="true" />
<add key="owin:AppStartup" value="HR_Web.StartupTest"/>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
I even tried to think of use MSAL.js, but it seems it's must to have Node.js.. But his project is use knockout.js therefore im not sure use node.js is a good solution or not yet
My startup class
[assembly: OwinStartup(typeof(HR_Web.StartupTest))]
namespace HR_Web
{
public class StartupTest
{
public void Configuration(IAppBuilder app)
{
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
ErrorHandler.Singleton().logInforDetail("Startup execution StartupTest Configuration started", LogTypes.FileAppenderRequestLog);
ConfigureAuth(app);
}
}
}