Copied to clipboard

Flag this post as spam?

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


  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Mar 22, 2010 @ 17:28
    Marc Love (uSkinned.net)
    0

    Password protect a custom section

    I have created a new custom section in umbraco and have located the files used for this section within the umbraco plugins folder. How do I password protect pages in this folder so that they are not directly accessible by entering the URL to the custom section directly into the address bar.

    ie: http://www.testwebsite.com/umbraco/plugins/management/films/films.aspx

    Cheers,

    Marc

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 22, 2010 @ 17:34
    Nik Wahlberg
    0

    You should set the 'Public Access' on the node/sub-codes using the right-click menu. You'll have the option here to select Role based protection (only if you have setup your user types and groups in the User section. Then, all you'll need is to drop in a user control with a .Net asp:Login form on it an you'll be good to go.

    Let us know if you need specific examples or take the forum search for a spin :) 

    Cheers,
    Nik

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Mar 22, 2010 @ 17:43
    Marc Love (uSkinned.net)
    1

     

    Hi Nik,

    I'm not sure if you know what I mean. I have added a new custom section that is accessed via the Umbraco admin interface. This is password protected as far as umbraco is concerned as I can control what users that are logged into umbraco are allowed access to my new section.

    The problem I have is that if someone knows the URL to my custom section which lives at:

    /umbraco/plugins/management/films/films.aspx

    They can access this section without going through the umbraco login.

    What I need to do is throw users back to the umbraco login page if they access this page directly. I tried adding the following to web.config but this resulted in the login page for my members login appearing in the left hand frame of the umbraco cms interface.

      <location path="umbraco/plugins/management">
        <system.web>
          <authorization>
            <deny users="?"/>
          </authorization>
        </system.web>
      </location>

     

     

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Mar 22, 2010 @ 17:44
    Marc Love (uSkinned.net)
    0

    Sorry that was meant to say 'right hand frame'

    doh

  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 22, 2010 @ 17:50
    Nik Wahlberg
    0

    Ah, sorry, I definitely misunderstood your issue. I don't know the answer to that. In fact, I have the same issue with one of my sites, and didn't even realize it!! Thanks for bringing it up. 

    This is an issue. Anyone got a solution?

    Cheers,
    Nik

  • Paul Sterling 718 posts 1534 karma points MVP 8x admin c-trib
    Mar 22, 2010 @ 18:03
    Paul Sterling
    5

    Hey all -

    There was a previous post on this same topic, but I cannot locate it.  At any rate, one solution is to handle the AuthorizeRequest event with a custom handler that maps to Umbraco members.  Here is the code we use for that:

        // add this snippet to web.config to hook up the httpModule
        //  <httpModules>
        //  <add name="AuthorizeEventHandler"
        //     type="MotusConnect.HttpModule" />
        //  </httpModules>

    namespace MotusConnect.HttpModule
    {
        public class AuthorizeEventHandler : IHttpModule
        {
            public AuthorizeEventHandler() { }

            public void Dispose() { }

            public void Init(HttpApplication context)
            {
                context.AuthorizeRequest +=new System.EventHandler(context_AuthorizeRequest);
            }

            private void context_AuthorizeRequest(object sender, System.EventArgs e)
            {
                // check roles here and allow access or redirect
                HttpApplication app = (HttpApplication)sender;
                HttpContext context = (HttpContext)app.Context;

                if (app.User.Identity.Name == null)
                {
                    // redirect to login
                    context.Response.Redirect(FormsAuthentication.LoginUrl);
                }
           
                // get required role for current page, if there is one
                bool allowed = false;

                foreach (string role in SiteMap.CurrentNode.Roles)
                {
                    if (context.User.IsInRole(role))
                    {
                        // ye shall pass if you are the right role
                        allowed = true;
                    }
                }

                // or not if you don't have the right role, no page for you
                if (!allowed)
                {
                    // redirect to login
                    context.Response.Redirect(FormsAuthentication.LoginUrl);
                }

                // you're in!
            }
  • Nik Wahlberg 639 posts 1237 karma points MVP
    Mar 22, 2010 @ 18:06
    Nik Wahlberg
    0

    Sweet! Thanks Paul. This will come in handy. Super!

    -- Nik

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Mar 22, 2010 @ 18:35
    Jan Skovgaard
    0

    Yes, super cool Paul :-)

    Maybe this should be posted in the WIKI as well?

    /Jan

  • Paul Sterling 718 posts 1534 karma points MVP 8x admin c-trib
    Mar 22, 2010 @ 18:50
    Paul Sterling
    0

    Feel free to post in the Wiki and collect the Karma points!

    -Paul

  • Jamie Howarth 306 posts 773 karma points c-trib
    Mar 22, 2010 @ 19:12
    Jamie Howarth
    0

    Wiki entries don't get karma cause they can have multiple editors :-) however feel free to share the love on the wiki nevertheless. I'll be using it for sure!

    Benjamin

  • Paul Sterling 718 posts 1534 karma points MVP 8x admin c-trib
    Mar 22, 2010 @ 19:30
    Paul Sterling
    0

    Karma points or not we all think highly of folks who created helpful Wiki entries!

    -Paul

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Mar 23, 2010 @ 11:47
    Marc Love (uSkinned.net)
    0

    Magic, thanks a lot guys for your help.

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Mar 23, 2010 @ 12:25
    Marc Love (uSkinned.net)
    1

    I have just found the following solution:

    Import umbraco.BusinessLogic on all of your pages within the custom section and then inherit your pages from umbraco.BasePages.UmbracoEnsuredPage

  • trfletch 598 posts 604 karma points
    Feb 16, 2011 @ 22:08
    trfletch
    0

    I know this is an old post but I also have this issue. Marc I like the sound of your solution but my pages already currently inherit from something. I am very new to asp.net but from what I have read you cannot inherit from more than one place. Is that right?

  • Marc Love (uSkinned.net) 432 posts 1691 karma points
    Oct 04, 2011 @ 11:47
    Marc Love (uSkinned.net)
    0

    Your pages will be inheriting from System.Web.UI.Page by default. Just replace this with umbraco.BasePages.UmbracoEnsuredPage and your pages will be password protected.

Please Sign in or register to post replies

Write your reply to:

Draft