Login

Friday, 04 April 2008

Accessing CurrentPage from a static context

by: Mari Jørgensen

Ever needed access to the CurrentPage object inside a static method or property?
As long as you have a valid HttpContext this code will do the trick

PageBase pageBase = HttpContext.Current.Handler as PageBase;
string pageName = pageBase.CurrentPage.PageName;

Comments

  1. Nice sample! However, I'm a bit confused - aren't these types of posts supposed to be published on labs.episerver.com? Or what's the purpose of blogs here at EPiServer World as opposed to those on Labs? Cheers!
  2. Well, we had the same discussion here in Norway just last week, without arriving to a conclusion. I'll look into it.
Comment post    
Please enter the text shown in the image: [No translation for /captcha/imagealternativetext, en]  
Submit
EPiTrace logger