Jump to:

23377 Posts in 18296 Topics by 2867 members

General Questions

SilverStripe Forums » General Questions » How can I deny users from directly accessing a page?

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1191 Views
  • BlueScreen
    Avatar
    Community Member
    36 Posts

    How can I deny users from directly accessing a page? Link to this post

    Most of the pages in the module I am building inherit from a single master page which contains common functions that all my pages share. I need to be able to access those functions from the rest of the pages with URL's like this (this is especially important for jquery):

    ww.site.com/masterpage/function

    To do that i used:

    Director::addRules(100, array(
       'masterpage' => 'masterpage_Controller',
    ));

    But this also means users can type in this:

    ww.site.com/masterpage

    And navigate directly to my master page which shows a blank page without any content. It would be great if this page returned a 404 error instead or redirected people to the mainpage

    I don't want to put in any code in the master page that could do that, as it would also affect all the other pages (I.E: if I placed ContentController::httpError(404) in there, then all my pages would return a 404)

    Is there some way to tell silverstripe "don't let anyone go to this specific URL"?

  • ekersten
    Avatar
    Community Member
    16 Posts

    Re: How can I deny users from directly accessing a page? Link to this post

    If the page is in your site tree you can simply change the page type to redirector page and send it to where ever you like.

    You could also set a redirect in the init() method of the controller and redirect based on the request url.

  • BlueScreen
    Avatar
    Community Member
    36 Posts

    Re: How can I deny users from directly accessing a page? Link to this post

    If I set the page up as a redirector page will I still be able to navigate to ww.site.com/masterpage/function and run that function? Or will it redirect anyone who tries to run the masterpage functions?

    Also I already tried putting Director::redirect() in the init() method of the master page, but that has the adverse affect of making ALL of my pages redirect the user because they all extend from the master!

    1191 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.