Views: 7930
Number of votes: 0
Average rating:

Accessing CurrentPage from a static context

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;
Apr 04, 2008

(By Guest, 9/21/2010 12:32:16 PM)

Nice sample! However, I'm a bit confused - aren't these types of posts supposed to be published on Or what's the purpose of blogs here at EPiServer World as opposed to those on Labs? Cheers!
/ Ted Nyberg

Mari Jørgensen
(By Mari Jørgensen, 9/21/2010 12:32:16 PM)

Well, we had the same discussion here in Norway just last week, without arriving to a conclusion. I'll look into it.

Please login to comment.