Pages

Thursday, December 9, 2010

SharePoint Site which uses Form Based Authentication redirects to a diffrenet Login Page during signout

Hello readers
Requirement:
When user clicks in either “Sign out” or “Sign in as different user”, they should redirect to the different login page not the default page in case of Form Based Authentication (FBA).
Solution:
We can do that by extending class with the “IHttpModule”. We have to write this two methods to redirect to a new page.
public void Init(HttpApplication app)
        {
            app.BeginRequest += new EventHandler(app_BeginRequest);
        }

        void app_BeginRequest(object sender , EventArgs e)
        {
            HttpContext context = HttpContext.Current;

            if (context.Request.Url.PathAndQuery.ToLower().Contains("/_layouts/accessdenied.aspx?loginasanotheruser=true") || context.Request.Path.ToLower().Contains("/_layouts/signout.aspx"))
            {

                context.Response.Redirect("redirectnewpage.aspx");

            }
        }
How to deploy?
  1. Put DLL inside theGAC and put the same dll inside bin folder of the webdirectory.
  2. Open the web.config file and add this section
Under <httpModules>
<add name="LearningVillageSigout" type="LearningVillageSigout.HttpModule" />

  1. Do IISRESET.

No comments:

Post a Comment