Tuesday, August 4, 2009

Bypassing the login.aspx (FBA) when a search result is clicked in Moss 2007

Problem statement

We had to create an intranet blog as well as an internet facing blog, both would have the same data. It would be treated like an "authoring" paradigm. Without going into too many details the FBA (Forms Based Authentication) was setup for the external site and windows authentication setup for the internal site compliments of Bramley.

Everything was cool until a problem popped up when the ANON user does a search and one of the search results is clicked. This then takes the user to the FBA login screen and wants the ANON user to log in before it will display the page. This becomes a major pain if users are asked every time they click on a search result to authenticate themselves.

It's such a simple change but took us a whole day and a half to figure out .... J

Go to your login.aspx page on the file server which can be found under the "layouts" folder in the 12 hive.

Add this code to the login.aspx

<script runat="server">

protected override void OnLoad(EventArgs e)

{

//returnWebUrl is the url of the search result that was clicked

string returnWebUrl= Server.UrlDecode(Request.QueryString["ReturnUrl"]);

//set the auth cookie and the redirect

FormsAuthentication.SetAuthCookie("anonymoususer", true);

Response.Redirect("http://sharepoint/"+returnWebUrl);

base.OnLoad(e);

}


</script>


And this should solve the problem of bypassing the FBA login.aspx screen when a search result item is clicked.

No comments:

Post a Comment