Copied to clipboard

Flag this post as spam?

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


  • Anju 9 posts 29 karma points
    Jan 25, 2012 @ 05:08
    Anju
    0

    Custom Login

    Hi,

    I would like to create a custom login page for my website and have to integrate with Umbraco.I would like to check a session value in master page and if there is no value available it will redirect to the login page and set the session there, otherwise it will display the home page of my website.

     

    Please help me ASAP.

     

    Regards

    Anju

  • Rodion Novoselov 694 posts 859 karma points
    Jan 25, 2012 @ 06:27
    Rodion Novoselov
    0

    Hi. Why for to invent a wheel? ASP.NET has a built-in mechanism for authentication. You just need to set it up properly and to turn to use a standard asp.net login control.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2012 @ 07:02
    Jeroen Breuer
    0

    Here is an example of a custom login control. It's fully customizable.

    .aspx

    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="Login.ascx.cs" Inherits="Project.WebApplication.UserControls.Login" %>
    
    <asp:Login ID="LoginMember" runat="server" FailureText="Het inloggen is niet gelukt, controleer uw gebruikersnaam en wachtwoord." RenderOuterTable="false">
        <LayoutTemplate>
            <asp:Panel runat="server" DefaultButton="LnkBtnLogin" CssClass="lgpanel">
                <label class="lglb tt">gebruikersnaam:</label>
                <asp:TextBox ID="UserName" runat="server" ValidationGroup="Login" CssClass="lginput"></asp:TextBox>
                <label class="lglb tt">wachtwoord:</label>
                <asp:TextBox ID="Password" runat="server" TextMode="Password" ValidationGroup="Login" CssClass="lginput"></asp:TextBox>
                <a href="<umbraco:Item field="passwordForgottenLink" recursive="true" runat="server"/>" class="pwdlink">Wachtwoord vergeten?</a>
                <asp:Checkbox id="RememberMe" runat="server" Text="Onthoud mijn login gegevens" Checked="false" CssClass="remember" />
                <br style="clear:right;" />
                <asp:LinkButton ID="LnkBtnLogin" runat="server" CommandName="Login" Text="Login" ValidationGroup="Login" CssClass="btn"></asp:LinkButton>
                <div class="failuretext_wrapper"><asp:Label id="FailureText" runat="server" style="color: White;"></asp:Label></div>
            </asp:Panel>
        </LayoutTemplate>
    </asp:Login>

    .cs

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //Set the page where to go after a user logged on.
            dynamic currentNode = new DynamicNode(Node.GetCurrent());
            LoginMember.DestinationPageUrl = library.NiceUrl(currentNode.sportLink);
        }
    }

    Jeroen

  • Anju 9 posts 29 karma points
    Jan 25, 2012 @ 07:06
    Anju
    0

    Thanks Jeroen.

    How we set this page as default page inside umbraco?

  • Rodion Novoselov 694 posts 859 karma points
    Jan 25, 2012 @ 07:24
    Rodion Novoselov
    0

    If you want that your login page would be a default one you just move it to the top of the content tree. In such a case you will also have to set defaultRedirect settings in the web.config file (<system.web>/<authentication>/<forms> section) to the start url of your site (like defaultRedirect="/home/"), so that to avoid redirecting back to the login page itself after logging in.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2012 @ 09:18
    Jeroen Breuer
    0

    You can add this usercontrol in a macro and place that on a template. Create a special login node and give it this template. You can watch a free video on how to do this here: http://umbraco.com/help-and-support/video-tutorials/introduction-to-umbraco/developer-introduction/using-net-user-controls/TVPlayer.

    I've never changed anything in web.config for a login system in Umbraco. You can set rights on nodes and there you can specify a login page if the user tries to visit that page while he is not logged in. By setting LoginMember.DestinationPageUrl you can specify to what page the user should go after he's logged in.

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 25, 2012 @ 10:49
    Rodion Novoselov
    0

    "By setting LoginMember.DestinationPageUrl you can specify to what page the user should go after he's logged in."

    Actually it's the same - if DestinationPageUrl is not set in the Login control then this control fallbacks to the defaultUrl from web.config.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jan 25, 2012 @ 10:55
    Jeroen Breuer
    0

    But why would you want to set it in the web.config? By using  LoginMember.DestinationPageUrl in the code you can use a node from umbraco which is selected with a content picker. That's more flexible and it can be changed in Umbraco by a user who has no rights to the web.config.

    Jeroen

  • Rodion Novoselov 694 posts 859 karma points
    Jan 25, 2012 @ 11:19
    Rodion Novoselov
    0

    Yeah, I understand, but old habits die hard :-) Of course when it comes to umbraco setting it through the property has lots benefits since it always allows to change its value through the backoffice.

Please Sign in or register to post replies

Write your reply to:

Draft