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 138 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 4908 posts 12265 karma points MVP 5x admin c-trib
    Apr 01, 2015 @ 14:26
  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    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 24 posts 176 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 1526 posts 5272 karma points MVP 3x
    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 24 posts 176 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 1526 posts 5272 karma points MVP 3x
    Mar 07, 2016 @ 12:45
    Shannon Deminick
    0

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

  • Ben Grice 24 posts 176 karma points
    Mar 08, 2016 @ 16:38
    Ben Grice
    0

    hi Sharon,

    It is compiled (Web Application).

  • zell 37 posts 90 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 1526 posts 5272 karma points MVP 3x
    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
    {
    
  • George Phillipson 108 posts 287 karma points
    Jan 25, 2020 @ 00:53
    George Phillipson
    0

    If anyone comes across this problem using Umbraco 8, this is how I fixed it.

    Web.config

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

    Startup.cs

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

    I found the above allows you to use your friendly name for OwinStartUp and also will enable you to log in to the back office.

  • Virginia Rochester 5 posts 95 karma points
    Jan 27, 2022 @ 17:21
    Virginia Rochester
    0

    Hi George, thanks for the information you gave on Umbraco 8. I'm trying to achieve the same thing in Umbraco 8 and followed your instructions but still my OwinStartup class is not being hit. Do I need to save the OwinStartup class in a particular location? I have just put it at the root of the Umbraco project, at the same level as the web.config file. Thanks.

  • HBSequence 6 posts 77 karma points
    Feb 11, 2020 @ 08:56
    HBSequence
    0

    Be careful if you are using breakpoints to test if your statup class is being loaded. Checkout this link: https://stackoverflow.com/a/22772759/1053594

    To test with break points:

    • Set the breakpoints
    • Start debugging
    • When your site loads, make a change to web.config and save (you can just add/remove whitespace)
    • Reload the site. Your breakpoints will now be hit.
  • George Phillipson 108 posts 287 karma points
    Jan 28, 2022 @ 10:10
    George Phillipson
    1

    Hi Virginia Rochester

    The startup class is in the root folder next to web.config

    If you set a breakpoint and run for the 1st time the breakpoint will be hit, see image,

    Once the page loads, and you refresh it will not get hit again unless you stop debugger and start again

    Hope it helps

    George

    enter image description here

  • Virginia Rochester 5 posts 95 karma points
    Jan 28, 2022 @ 14:31
    Virginia Rochester
    0

    Thanks George, that did help. I appreciate you responding. Virginia

Please Sign in or register to post replies

Write your reply to:

Draft