Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Ryan 34 posts 136 karma points
    Apr 01, 2015 @ 11:34
    Ryan
    0

    OWIN Startup

    Hi all,

    I'm hoping someone can help me, I have a method that I want to run on start up. I've looked at similar topics and made the changes that I thought would fix my issue, unfortunately not - The method in question is never executed when I start my application. Any help is greatly appreciated :)

    using Microsoft.AspNet.Identity;
    using Microsoft.Owin;
    using Microsoft.Owin.Security.Cookies;
    using Owin;
    using Umbraco.Core;
    
    [assembly: OwinStartup("ConfigureAuth",typeof(UmbracoIntV2.App_Start.UmbracoIdentityStartup))]
    
    namespace UmbracoIntV2.App_Start
    {
    public class UmbracoIdentityStartup : ApplicationEventHandler
    {
        public void ConfigureAuth(IAppBuilder app)
        {
           //some code
         }
       }
    }
    
  • Jeroen Breuer 4860 posts 12127 karma points MVP 3x admin c-trib
    Apr 01, 2015 @ 14:26
  • Shannon Deminick 1488 posts 5014 karma points hq
    Apr 02, 2015 @ 14:26
    Shannon Deminick
    0

    Why is it inheriting from ApplicationEventHandler ?

    An example: https://github.com/umbraco/Umbraco-CMS/blob/7.3.0/src/Umbraco.Web/UmbracoDefaultOwinStartup.cs

    Since you are NAMING your attribute you need to apply that in web.config:

    You don't have to name your startup, see docs: http://www.asp.net/aspnet/overview/owin-and-katana/owin-startup-class-detection

  • Ben Grice 20 posts 151 karma points
    Feb 26, 2016 @ 15:29
    Ben Grice
    0

    Hello all,

    I have a similar issue using Umbraco 7.3.4. I'm trying to use SignalR but I'm so far been unable to run the code in the Configuration method below. I've added a breakpoint on the base.Configuration(app) line but this never gets hit

    using Microsoft.Owin;
    using Owin;
    using Umbraco.Web;
    
    [assembly: OwinStartup("BenTestStartup", typeof(Intranet2.App_Start.Startup))]
    namespace Intranet2.App_Start
    {
        public class Startup : UmbracoDefaultOwinStartup
        {
            public override void Configuration(IAppBuilder app)
            {
                base.Configuration(app);
                app.MapSignalR();
            }
        }
    }
    

    I have remove the default and added the key to the web.config

    <!--<add key="owin:appStartup" value="UmbracoDefaultOwinStartup" />-->
    <add key="owin:appStartup" value="BenTestStartup" />
    

    Is there anything obvious that I could have missed which would mean my Configuration method would not run?

  • Shannon Deminick 1488 posts 5014 karma points hq
    Mar 07, 2016 @ 10:46
    Shannon Deminick
    0

    Is this still an issue for you? Your code/config looks fine and your Configuration should be hit

  • Ben Grice 20 posts 151 karma points
    Mar 07, 2016 @ 10:56
    Ben Grice
    0

    Hello Sharon,

    Yes, this is still an issue for me. Fortunately, the requirement to use SignalR has been dropped, but I will need to get this going again in the near future.

    I tinkered with things a bit... I tried a brand new Web Application in Visual Studio, and then installed Umbraco through NuGet (7.4.1 I think), and then SignalR, but I still couldn't get the breakpoint to be hit. If I installed SignalR straight into a Mvc application (not Umbraco), then the breakpoint would be hit. If the requirement to use SignalR had still existed, I was going to try to call app.MapSignalR from within an ActionFilter or an AuthorisationFilter (as I would have done in Mvc).

    As you say my code looks fine (and I've repeated on another project), I suppose I could have missed something somewhere along the line.

    Does a working version of an Umbraco Solution file with SignalR installed exist which I can download to test locally?

    Thanks for your help Ben

  • Shannon Deminick 1488 posts 5014 karma points hq
    Mar 07, 2016 @ 12:45
    Shannon Deminick
    0

    Is this startup class in your App_Code or is it compiled?

  • Ben Grice 20 posts 151 karma points
    Mar 08, 2016 @ 16:38
    Ben Grice
    0

    hi Sharon,

    It is compiled (Web Application).

  • zell 37 posts 88 karma points
    Apr 01, 2016 @ 04:08
    zell
    0

    same issue for me on 7.4.1 i want to use my own startup .. removing "owin:appStartup":"UmbracoDefaultOwinStartup" breaks the backoffice but my startup class is hit. adding it back in means my startup is never hit.

    EDIT: worked it out. durrhhh. stupid me.

    Create a Startup.cs and comment out "owin:appStartup":"UmbracoDefaultOwinStartup" , OWIN obviously looks for Startup by default. just need to inherit UmbracoDefaultOwinStartup

    using System;
    using Microsoft.Owin;
    using Owin;
    using Umbraco.Web;
    
    [assembly: OwinStartup(typeof(Startup))]
    namespace My.Site
    {
        public class Startup : UmbracoDefaultOwinStartup
        {
            public new void Configuration(IAppBuilder app)
            {
                base.Configuration(app);
                //my own startup functions
            }
        }
    }
    
  • Shannon Deminick 1488 posts 5014 karma points hq
    Apr 01, 2016 @ 06:41
    Shannon Deminick
    0

    It's mostly because of the way you've declared your start-up class, you haven't named it in your Owin start-up attribute. What you've done will work but it's not best practices for Umbraco. You should use an overload on that attribute to give it a name and then use this name in your web config owin start-up declaration. Like this https://github.com/umbraco/UmbracoIdentityExtensions/blob/master/src/Umbraco.IdentityExtensions/App_Start/UmbracoStandardOwinStartup.cs.pp

  • Nico 10 posts 77 karma points
    Feb 07, 2017 @ 07:30
  • Shahid Iqbal 3 posts 71 karma points
    Oct 10, 2018 @ 10:06
    Shahid Iqbal
    0

    This articles explains exact implementation details of integrating Owin in Umbraco 7

    https://blog.indivirtual.nl/umbraco-7-3-and-oauth-2-0/

  • Rick Atkinson 1 post 71 karma points
    Jul 25, 2019 @ 16:51
    Rick Atkinson
    0

    I had this issue, put a breakpoint in the code, never hit.

    Spotted that in the app config the following owin startup was defined.

    <add key="owin:appStartup" value="UmbracoDefaultOwinStartup" />
    

    swapped it to

    <add key="owin:appStartup" value="UmbracoStandardOwinStartup" />
    

    works perfectly now.

    [assembly: OwinStartup("UmbracoStandardOwinStartup", typeof(UmbracoStandardOwinStartup))]
    
    public class UmbracoStandardOwinStartup : UmbracoDefaultOwinStartup
    {
    
Please Sign in or register to post replies

Write your reply to:

Draft