Getting Root Site in Sharepoint
12/11/2009 Leave a comment
When you are working in sharepoint with extended web applications which is using different authentication methods . You have to need current URL of different domain for hardcoded envoriment . For example http://www.test.com one of your extranet using forms authentication and http://myserver is your default and using windows authentication. if user create a request from http://www.test.com/somedifferet… you need to root of http://www.test.com rather than http://myserver.And you dont want a login screen because of links.
if you type hard code like this its not working for default domain which image not in _layout folder.
<img src=”http://myserver/something/imagenotcomingfromlayout.jpg”> asks extra windows auth login
Solution.
<img src=”/_layouts/GetRootSite.ashx?url=http://myserver/something/imagenotcomingfromlayout.jpg”>
Handlers returns same as users coming request root site.and change http://myserver/ to http://www.test.com
Create a generic handler like below and add this handler to 12/TEMPLATES/LAYOUTS folder for every registered user can reach.
<%@ WebHandler Language=“C#” Class=“GetRootSite” %>
using System;
using System.Web;
using System.Net;
public class GetRootSite : IHttpHandler
{
public void ProcessRequest (HttpContext context) {
Uri requestUri = context.Request.Url;
string baseUrl2 = context.Request.Url.GetLeftPart(UriPartial.Authority);
string gelenpath = context.Request.QueryString[“url”];
Uri gelen = new Uri(gelenpath);
string gelenPreFix = gelen.GetLeftPart(UriPartial.Authority);
string artakalan = gelenpath.Substring(gelenPreFix.Length);
string sonuc = baseUrl2 + artakalan;
context.Response.Redirect(sonuc);
}
public bool IsReusable {
get {
return false;
}
}
}