Monday, 6 February 2012

Custom sign out SharePoint page for FBA user.


Hi, everyone!
In my latest project we are using FBA users for our portal. And in the prototype of the master page such as generic web page we have login control with username, password boxes and ‘sing in’ button. If you will use for login just general sign in control of ASP .NET we will lose with authentication, exception will appear in the page. For fixing this problem we have to use SPClaimsUtility.
For example:
protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    e.Authenticated = 
SPClaimsUtility.AuthenticateFormsUser(Request.Url, signIn.UserName, 
signIn.Password);
}
But for sign out we have to create custom page for logout current user from portal. In all forums you can find information that’s you can use default signout.aspx page from 14 hive. But it’s true if you created custom login page inherited from SharePoint SignInPage. Default page is working incorrectly, it made sign out but doesn’t remove cookies from browser and the next page what you will see after signout, it will ‘Exception … ArgumentException … encodedValue’.
Insert the next following code to the page for clearing sign out.
protected override void OnLoad(EventArgs e)
{
 base.OnLoad(e);

 FormsAuthentication.SignOut();
 var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        // Clear .ASPAUTH cookie key.
 if (authCookie != null)
 {
  var myCookie = new HttpCookie(authCookie.Name)
               {Expires = DateTime.Now.AddDays(-1)};
  Response.Cookies.Add(myCookie);
 }

 SPIisSettings iisSettingsWithFallback = 
        
 Site.WebApplication.GetIisSettingsWithFallback(Site.Zone);
 if (iisSettingsWithFallback.UseClaimsAuthentication)
 {
  FederatedAuthentication.SessionAuthenticationModule.SignOut();
                // Clear FedAuth Cookie key
  FederatedAuthentication.SessionAuthenticationModule.DeleteSession       
 TokenCookie();
 }


 SPUtility.Redirect(Web.ServerRelativeUrl, SPRedirectFlags.Default,
       
   Context);
}
That’s all what you need to add to the custom sign out page.

4 comments:

  1. Thank you for another fantastic poѕt. Where еlse could anybody get that type of іnformation in such а perfeсt manner of writing?
    Ι've a presentation subsequent week, and I am at the search for such info.

    Also visit my web blog Click Us *elgg.elisabethinum.ac.at*

    ReplyDelete
  2. Нellο there! Dο you use Тwіtteг?

    I'd like to follow you if that would be okay. I'm definitely enjoying уour
    blog and look forward to new updates.

    my web-site; High Stakes Bonus

    ReplyDelete
  3. I think evеrythіng ωгote was
    actually very rеasonablе. Howеѵer, consіder this, suppoѕe you compoѕed a сatchieг title?
    I аm not ѕuggeѕting уοur content is nοt ѕolid.
    , however suρposе you aԁded something that grabbed
    folk's attention? I mean "Custom sign out SharePoint page for FBA user." is a little vanilla. You could peek at Yahoo's front page anԁ watch hοω they
    crеate pоst heaԁlіnеs to get vieωers to click.
    You might aԁd a ѵіdeo oг a pic or two
    to get reаders intereѕted about everything've written. Just my opinion, it could make your website a little bit more interesting.

    my site - CarbonPoker Offer ()

    ReplyDelete
  4. Ρiece οf ωriting wгiting iѕ alsο
    a excitement, if yοu be familіаr ωith
    afterωаrd you cаn wгite or elsе it
    is complіcаtеd tο wгite.


    Feel free to visit my blog poѕt: Ameгісas Cardгοom Pokеr Offеr ()

    ReplyDelete