Monday, December 6, 2010

Forms Based Authentication in SharePoint 2010 - Part 2

<< Forms Based Authentication in SharePoint 2010 - Part 1

Custom Login Form

You Can create a custom login form for your FBA enabled web application in following steps…

  • Locate _forms folder of your webapplication (C:\inetpub\wwwroot\wss\VirtualDirectories\port\_forms)

  • Create a new folder FBA in _forms;

  • Create new page Login.aspx in FBA Folder; add all Resources in this folder e.g. images

  • Open web.config file of FBA enabled web application

  • Change Authentication login page to your custom page ;


    <authentication mode="Forms">
    <!--<forms loginUrl="/_login/default.aspx" />-->
    <forms loginUrl="/_forms/FBA/login.aspx" protection="All" timeout="30" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.aspx" cookieless="UseDeviceProfile" enableCrossAppRedirects="false" />
    </authentication>


  • For creating Custom login.aspx , copy existing Default.aspx from _forms root folder to FBA folder , rename it to login.aspx and change html as you wish ; A sample login.aspx can be …

    <asp:Content ID="Content4" ContentPlaceHolderId="PlaceHolderMain" runat="server">

    <div style="text-align:center;margin-top:110px;">
    <asp:login id="signInControl" FailureText="<%$Resources:wss,login_pageFailureText%>" runat="server" BorderPadding="4" ForeColor="#333333" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" width="100%" BackColor="#EFF3FB" BorderColor="#B5C7DE" BorderStyle="Solid" >
    <TitleTextStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Size="0.9em" />
    <InstructionTextStyle Font-Italic="True" ForeColor="Black" />
    <TextBoxStyle Font-Size="0.8em" />
    <LoginButtonStyle BackColor="White" BorderColor="#507CD1" BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" ForeColor="#284E98" />
    <layouttemplate>
    <asp:label id="FailureText" class="ms-error" runat="server"/>
    <div style="width:350px;border:solid 1px #ECF5FF;padding:3px; background-color:white;">

    <table width="100%" border="0" cellspacing="0" cellpadding="3" style="border:solid 1px #ECF5FF;background-color:#F9FCFF ;background-image:url(/_forms/FBA/Images/lockBG.jpg);background-repeat:no-repeat;">
    <tr>
    <td colspan="2" style="color:#003399;font-size:13px;font-weight:bold;background-color:#F9FCFF;background-image:url(/_forms/FBA/Images/gradiantBlue.jpg); background-repeat:repeat-x; border-bottom:solid 1px #ECF5FF;padding-bottom:8px;">Member Login</td>
    </tr>
    <tr>
    <td align="right" style="padding-top:8px; width: 142px;font-size:12px;" nowrap="nowrap">
    <SharePoint:EncodedLiteral ID="EncodedLiteral1" runat="server" text="<%$Resources:wss,login_pageUserName%>" EncodeMethod='HtmlEncode'/>
    </td>
    <td style="padding-top:8px; width: 300px;">
    <asp:textbox id="UserName" autocomplete="off" runat="server" class="ms-inputuserfield" width="99%" />
    <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName"
    ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="login">*</asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td align="right" style="width: 142px;font-size:12px;" nowrap="nowrap">
    <SharePoint:EncodedLiteral ID="EncodedLiteral2" runat="server" text="<%$Resources:wss,login_pagePassword%>" EncodeMethod='HtmlEncode'/>
    </td>
    <td style="padding-top:8px; width: 300px;">
    <asp:textbox id="password" TextMode="Password" autocomplete="off" runat="server" class="ms-inputuserfield" width="99%" />
    <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
    ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="login">*</asp:RequiredFieldValidator>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="right" style="font-size:11px;">
    <asp:button id="login" commandname="Login" text="<%$Resources:wss,login_pagetitle%>" runat="server" Font-Names="Verdana" ForeColor="#284E98" ValidationGroup="login" />
    </td>
    </tr>
    <tr>
    <td colspan="2" >
    <asp:checkbox id="RememberMe" text="<%$SPHtmlEncodedResources:wss,login_pageRememberMe%>" runat="server" />
    </td>
    </tr>
    </table>
    </div>
    </layouttemplate>
    </asp:login>
    </div>

    </asp:Content>







1 comment:

Form Samples said...

Really tis code was very helped me a lot. Thanks to share with us!