Getting Root Site in Sharepoint

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 one of your extranet using forms authentication and http://myserver is your default and using windows authentication. if user create a request from… you need to root of 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”&gt; asks extra windows auth login


<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

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;

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;



public bool IsReusable {

get {

return false;