Saturday, August 24, 2013

Creating Custom Log Out page in SharePoint 2010/ 2013.

Hi friends,
This post is about how to create Custom Log out page in SharePoint. This customization is required when you implement FBA ( Form Based Authentication) or Mix mode authentication in SharePoint. When FBA is implemented with custom Log-in, it does not clear authentication Cookies automatically so to clear authentication cookies we need to do some customization. This customization is done using custom logout page where some block of java-script code is written:

This block of code also helps to prevent error while logging out using FBA.

Following steps are carried out while creating custom log out page in SharePoint with

1.       First Create a logout.aspx using SharePoint Designer
è Open your site using SharePoint designer-> Go to site pages->click on Page button on top ribbon and select ASPX page.
è It will create an aspx page in site pages rename it to Logout.aspx
è Double click on page, it will open page designer, Check Out the page and click on edit file link to open in edit mode.
è Add page title to: Lout out
è Add bellow Script in <head> section:
<script type="text/javascript">
function LogOutBodyOnLoad()
{
try
{
   /* Note : this command is support with only IE  */
  document.execCommand("ClearAuthenticationCache",false);
  window.close(); // It asks to close browser after logout.
  }
  catch (e) { }
 window.location='/_layouts/signout.aspx'; // Redirects to sign out page of SharePoint.
 }
 </script>
è In <body> section change as bellow:
<body onload="LogOutBodyOnLoad ()">
è Check in your Logout.aspx page after performing above changes.
è Next you need to call this Logout.aspx on click of Log out button on Welcom.aspx page that is master page of your site.
è Before change master page you need to check which master page is used by your application to check it go to Site Action->Site setting-Look and feel->Master page. It will show you which master page is used in your application.
è Go to SharePoint Designer -> click on master page in left navigation -> take copy of your master page. If you are working in SharePoint 2013 then you will get ( oslo.htm, oslo.master, seattle.html and seattle.master). Open only ( .html) page in designer and add below script on head section of master page which your application is using. ( check out your master page before editing )
<script type="text/javascript" src="/_catalogs/Scripts/jquery-1.4.1.min.js"></script>
<script type="text/javascript" >
$(document).ready(function(){$("#zz4_ID_Logout").attr("onMenuClick","STSNavigate2(event,'/Site Pages/Logout.aspx');");});
</script>
è Add jquery fie to _catelogs/Scripts using SharePoint designer. If script folder does not exist in _catelogs crate it and add jqury file in it. Check proper version of jquery file with the master page tag.  Jquery file is added in _catelogs using SharePoint designer.
è If you are using SharePoint designer then Id of Logout control may be different, it may be zz3_ID_Logout or zz4_ …. So to get right ID login to your portal and check Source of page, Search for Log out and get right control ID. Replace control ID in Master page’ javascript tag with the right one.


è That’s it now you can login in to your portal and can identify title of log out page after clicking log out button. This could is mainly written to clear authentication cookies after logout.

That's it.. Fell free to ask any question regarding this post.

Happy Coding 
Regards
Gireesh Painuly..

No comments:

Post a Comment