SharePoint - how to get the full URL of the current page in code behind

SharePoint - how to get the full URL of the current page in code behind

this code works for me, for pages under _layouts and also for 'normal' pages under the site:


       string thisPageUrl;  
       if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("_layouts"))  
       {  
         thisPageUrl = SPContext.Current.Web.Url + context.Request.Path; //note: cannot rely on Request.Url to be correct !  
       }  
       else  
       {  
         thisPageUrl = HttpContext.Current.Request.Url.ToString();  
       }  

Comments