0

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);
    }
}
}
DevT
  • 4,843
  • 16
  • 59
  • 92
  • Show us your `Global.asax.cs` file _and_ more of your `web.config` file. And may I ask why you're still using WebForms in 2023? – Dai Jul 17 '23 at 13:11
  • @Dai updated the question.. well this is really old project and they need to have microsoft authentication now.. its done using asp.net web forms and knockout.js – DevT Jul 17 '23 at 13:34
  • Answer from 2022 should help you identify what changed, https://stackoverflow.com/a/73120638/11182 – Lex Li Jul 17 '23 at 14:45
  • @DevT the url hardcoded in your Application_Start looks like a development server. Is that the correct IIS url and port? – derloopkat Jul 18 '23 at 08:31
  • @derloopkat that approach is not working even in development environment. in that case im getting System.InvalidOperationException: 'No owin.Environment item was found in the context.' – DevT Jul 18 '23 at 09:30
  • 1
    Do you have an OWIN server loaded in your application? Make sure you have installed the required OWIN packages such as Microsoft.Owin.Host.SystemWeb. – YurongDai Jul 25 '23 at 07:20

0 Answers0