Monday, December 30, 2013

Create FBA custom Login page in SharePoint 2013

Changes in the Authentication providers:

_layouts/15/SP.FBA/LoginClaims.aspx






After you configure FBA : post


Create a Application page put the HTML tags as below

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LoginClaims.aspx.cs" Inherits="FBA.LoginClaims" MasterPageFile="~/_layouts/15/errorv15.master" %>
<%@ Assembly Name="Microsoft.SharePoint.IdentityModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">

</asp:Content>

<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
   


<asp:Label ID="Name" runat="server" Text="UserName:"/>

<br/>

<asp:TextBox ID="txtUserName" runat="server" Height="22px"/>

<br />

<asp:Label ID="lblPwd" runat="server" Text="Password:"/>

<br/>

<asp:TextBox ID="txtPwd" runat="server" TextMode="Password" 

                                        Height="22px"/>

<br />


<asp:Button ID="btnLogIn" runat="server" Text="Sign In" 

                          onclick="btnLogIn_Click"/>

                    

<br /><br />

<asp:Label ID="lblMsg" runat="server" Text=""/>


</asp:Content>

<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
Application Page
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea" runat="server" >
Vendor Login site..
</asp:Content>




Server side code:

using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.IdentityModel;
using Microsoft.SharePoint.IdentityModel.Pages;
namespace FBA
{
    public partial class LoginClaims : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }
        protected void btnLogIn_Click(object sender, EventArgs e)
        {
            if ((txtUserName.Text.Length > 0 && txtPwd.Text.Length > 0))
            {
                bool authenticated = SPClaimsUtility.AuthenticateFormsUser(Context.Request.UrlReferrer, txtUserName.Text, txtPwd.Text);
                if (!authenticated)
                {
                    lblMsg.Text = "Invalid Username or Password";
                }
                else
                {
                    Response.Redirect(Context.Request.QueryString["ReturnUrl"].ToString());
                }
            }
            else
            {
                lblMsg.Text = "Username or Password can't be empty";
            }
        }

    }

 
}

No comments:

Post a Comment

HTML

Script:

JS