1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / OnUnauthorizedAccess method is not being called when unauthorized access happens

OnUnauthorizedAccess method is not being called when unauthorized access happens

1 posts, 0 answered
  1. kaarthick
    kaarthick avatar
    1 posts
    Registered:
    04 Jul 2016
    12 Dec 2016
    Link to this post

    My MVC application is configured to have both admin login(backend users) and membership provider(for normal users),

    When normal user login, they have to be restricted to backend sitefinity which happens now.

    Now i need to set custom error page showing them they arent allowed to access the backend.

    I followed this link - http://www.sitefinity.com/blogs/stefani-tacheva-s-blog/2014/03/11/redirect-unauthorized-users-to-a-custom-page

     to redirect the user to custom error view ~/Error/NotFound.

     

    My Global.asax file is as follows,

    protected void Application_Start(object sender, EventArgs e)
            {
                //subscribe to Bootstrapper.Initialized event
                Bootstrapper.Initialized += new EventHandler<Telerik.Sitefinity.Data.ExecutedEventArgs>(Bootstrapper_Initialized);
            }

     void Bootstrapper_Initialized(object sender, Telerik.Sitefinity.Data.ExecutedEventArgs e)
            {
                if (e.CommandName == "Bootstrapped")
                {
                    //use UnauthorizedPageAccessEvent
                    EventHub.Subscribe<IUnauthorizedPageAccessEvent>(new Telerik.Sitefinity.Services.Events.SitefinityEventHandler<IUnauthorizedPageAccessEvent>(OnUnauthorizedAccess));
                }
            }

            void OnUnauthorizedAccess(IUnauthorizedPageAccessEvent unauthorizedEvent)
            {
                var url = unauthorizedEvent.Page.Url.TrimStart('~');
                //for this specific page redirect to CustomerLoginPage
                if (unauthorizedEvent.Page.Title.Contains("needadminrights"))
                    unauthorizedEvent.HttpContext.Response.Redirect("~/Error/NotFound");
            }

     

     

    I had kept break points and it hits application start() and  Bootstrapper_Initialized(). When normal user tries to access localhost:yyyyy/sitefinity after authenticated , it does not hit OnUnauthorizedAccess() method nor invokes unauthorizedEvent.

    I expect the normal user is unauthorized to access localhost/sitefinity and should be taken to Error view ~\Error\NotFound.

     

     

     

1 posts, 0 answered