Login to view pageCancel

I would like to have the general public view all pages but two. On these two pages I would like a login prompt if someone tries to access the pages. I saw a few things in 3.0 where you could just check the [require login to this page] is there a way to do this in 4.0?
Thanks,
Charles

In 4.0 in order to be able to view a page two conditions need to be true:

1. The user has to be authenticated
2. The user needs to have the proper permissions to the page

What I'd suggest is to set the permissions to these two pages that you want to make non-accessible to the general public. You can do that by going to ~/Sitefinity/Pages and selecting Edit... >> Permissions from the Actions dropdown to the right of the page. The functionality you'll achieve this way is that once authenticated only the users who have the permissions to view these pages can go to them, the others simply won't be able to see this link using the Sitefinity navigation.

If you do insist on having the login, I guess you are developing a custom navigation menu, where the links to these two pages are visible to the general public. In this case it's possible to develop a custom logic that checks if the user is authenticated and if a user-defined string is contained in the url. This logic can lead to the Sitefinity login screen. Please see the code samples below to get a clearer idea of my suggestion.

The way I see it is the following - all your pages are by default set to View by Everyone (i.e. no authentication required to view them). For the two pages that you want to apply log in control, you can apply the sample logic that I gave you - it checks if the user is authenticated, and if not it will require him to log in.

Thanks for the quick reply...
Being new to sitefinity I may need a little more direction. I do not seem to have access to the code through the [edit in visual studio] link on the project manager. It open the project but none of my pages are there and I do not see the login widget... I'm sure its just me but do a simple login in just ASP.NET without sitefinity is very easy I'm not sure why it is seeming to be so complicated (for me) using sitefinity?
What pages do the below code go to and how do I open them?
Are there any tutorials on the subject or blogs or something?

As far as I have made it using sitefinity.... would be this approach.
create a link on the menu bar (looks like a link to a page) ----> create a blank page with a login control on it---->under that page move the page I want the login to access----> hook up the login to my roles

The code sample that I gave you refers to adding programatically a custom page your project in Visual Studio. The pages you create in Sitefinity cannot be seen in Visual Studio because they are dynamically created.

Your logic is right,thanks for pointing out the need for this functionality, I've logged it as a feature request and we'll be working on it. For now I'll try to give you two options to work around this feature.

Option one is to put a LogIn control on your page in Sitefinity (see Login Widgets Group article in the User Guide). Then you can set the view permissions to all the widgets on this page individually, and this way until a user is logged in the contents of the page will not be visible, just the login control. Since this requires individual setting of the view permissions for every widget on your page I'd recommend you to do it in a template, thus you can apply it to multiple pages.

Option two is to create a LoginToMyPage which contains only the login control, and set it up so that it redirects to your MyPage (the one that requires login to be seen). You can find instructions on how to set the redirect on this link from the User Guide.
Make sure to untick the Show in Navigation checkbox from MyPage properties ( you can find information on how to set page properties here) and to set its view permissions accordingly. This way you can only navigate to MyPage through LoginToMyPage (MyPage will not be shown in the menu).

- Doing it the code-way is not an option for me because the pages are dynamic,
so no access to the Page_Load event handler.

- Doing it the controls-way seems to be a bit long-winded. Having to go round every
single control and setting permissions. Then you have to remember when you are
adding new controls that you need to set the permissions.

- I am wondering if a JavaScript snippet can be dropped onto the page which would
accomplish the C# example given by Boyan? Perhaps an example by Telerik???

I managed to fix the issue by adding code to the MasterPages.
I am checking if the current page url contains the name of the
page of area that is protected. And if it contains the name then
a redirect occurs with a message in the parameters to inform the user
on the login screen why they have to login again.

It seems to work. I was going to drop a control ASCX that did this check
in its Load event handler, but there are issues about the order the
controls are executed in, so did the above instead.

You can set the permissions to that page that you want to make users log in to be able to browse. Do the following - go to Sitefinity Backend>>Pages and set the permissions of the desired page, where you explicitly forbid Anonymous role from Viewing this page. Then, every time an anonymous user tries to access this area of your website an error will be thrown (403 Forbidden). You can catch this error either in IIS or in custom errors in the web.config. You can find more information on how to set these on this forum thread (please note the settings are done the same way, just for 403 error in your case, not 404)

Webinars

Tools

Progress, Telerik, Sitefinity and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries.