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

Forums / General Discussions / Login to view page

Login to view page

11 posts, 0 answered
  1. charles
    charles avatar
    6 posts
    Registered:
    23 Dec 2010
    21 Feb 2011
    Link to this post
    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
  2. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    08 Dec 2016
    22 Feb 2011
    Link to this post
    Hi 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.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="SitefinityWebApp.WebForm2" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <asp:ScriptManager runat="server" ID="test11"></asp:ScriptManager>
        <div>
        <%--Let's say you're using radMenu for your custom site navigation, and the page "test" should not be seen
        by non-authorized users unless they authenticate--%>
         <telerik:RadMenu runat="server" ID="MenuItem1">
          <Items>
             <telerik:RadMenuItem runat="server" Text="test"  NavigateUrl="~/test"></telerik:RadMenuItem>
          </Items>
          </telerik:RadMenu>
     
        </div>
        </form>
    </body>
    </html>

    and in the code behind you write your custom logic
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    namespace SitefinityWebApp
    {
        public partial class WebForm2 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                var items = MenuItem1.Items;
                foreach (RadMenuItem item in items)
                {
                    if(!User.Identity.IsAuthenticated) 
                    {
                        item.NavigateUrl = "Sitefinity/Login?ReturnUrl=" + item.Text; //setting the ReturnUrl to the page where you navigated from
                    }
                }
                
            }
        }
    }

    I hope this information helps. Please let me know if I can assist you any further with this service request. Thank you in advance.

    Greetings,
    Boyan Barnev
    the Telerik team
  3. charles
    charles avatar
    6 posts
    Registered:
    23 Dec 2010
    22 Feb 2011
    Link to this post
    Thank you for the relpy. If the site is open to the public (no login) how would your suggestion work? I did not want a fornt end login but only to have a login on the two pages..
  4. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    08 Dec 2016
    22 Feb 2011
    Link to this post
    Hello charles,

    Thank you for getting back to me.

    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.

    I hope this information helps. I will be glad to assist you further.


    Greetings,
    Boyan Barnev
    the Telerik team
  5. charles
    charles avatar
    6 posts
    Registered:
    23 Dec 2010
    22 Feb 2011
    Link to this post
    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

    Thanks...
  6. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    08 Dec 2016
    23 Feb 2011
    Link to this post
    Hi charles,

    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).

    All the best,
    Boyan Barnev
    the Telerik team
  7. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    11 Mar 2011
    Link to this post
    Hi,

    I have an area of my website where you need to be logged in to view.
    For that I have a specific Login page. The rest of the website is available
    to view to anyone. 

    I have set the below:
    <authentication mode="Forms">
      <forms name=".ASPNET" loginUrl="~/Briefing" protection="All" timeout="1440" path="/" />
    </authentication>

    And changed the permission on the pages. Now when I navigate to it as anonymous, i get an ugly error saying no permissions.

    How do I get it to bounce the user to the login screen?

    Thanks,
    Andrei


  8. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    14 Mar 2011
    Link to this post
    Ok, 

     - 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???

    Many thanks,
    Andrei 
  9. Andrei
    Andrei avatar
    553 posts
    Registered:
    27 Nov 2008
    15 Mar 2011
    Link to this post
    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.

    Many thanks,
    Andrei
  10. Chris
    Chris avatar
    11 posts
    Registered:
    07 Mar 2011
    22 Mar 2011
    Link to this post
    Andrei,

    Can you provide a code snippet of how you were able to do this inside of your MasterPage? 
  11. Boyan Barnev
    Boyan Barnev avatar
    1429 posts
    Registered:
    08 Dec 2016
    23 Mar 2011
    Link to this post
    Hello Chris,

    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)

    Best wishes,
    Boyan Barnev
    the Telerik team
11 posts, 0 answered