c# - Get current System.Web.UI.Page from HttpContext? -


this 2 part question. first,does httpcontext.current correspond current system.ui.page object?

and second question, related first, why can't use following see if current page implements interface:

private iwebbase findwebbase() {     if (httpcontext.current iwebbase != null)     {         return (iwebbase)httpcontext.current.;     }     throw new notimplementedexception("crawling iwebbase not implemented yet"); } 

the general context controls need know whether executing sharepoint webpart, or part of asp.net framework.

i have solved problem requiring control pass reference itself, , checking page property of control, i'm still curious why above not work.

the compiler error is: cannot convert system.web.httpcontext ...iwebbase via reference conversion, boxing conversion, unboxing conversion, wrapping conversion or null type conversion.

no, msdn on httpcontext.current: "gets or sets httpcontext object current http request."

in other words httpcontext object, not page.

you can page object via httpcontext using:

page page = httpcontext.current.handler page;  if (page != null) {      // use page instance. } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -