<p>This is actually a two part question. First,does the HttpContext.Current correspond to the current System.UI.Page object?</p>

<p>And the second question, which is probably related to the first, is why can't I use the following to see if the current page implements an interface:</p>

<pre><code>private IWebBase FindWebBase()
{
    if (HttpContext.Current as IWebBase != null)
    {
        return (IWebBase)HttpContext.Current.;
    }
    throw new NotImplementedException("Crawling for IWebBase not implemented yet");
}
</code></pre>

<p>The general context is that some controls need to know whether they are executing as a SharePoint webpart, or as part of an Asp.Net framework.</p>

<p>I have solved the problem by requiring the control to pass a reference to itself, and checking the Page property of the control, but I'm still curious why the above does not work.</p>

<p>The compiler error is:
Cannot convert System.Web.HttpContext to ...IWebBase via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion or null type conversion.</p>

[{'answer_id': 58128, 'author': 'Kilhoffer', 'author_id': 5469, 'author_profile': 'https://Stackoverflow.com/users/5469', 'pm_score': 5, 'selected': False, 'text': "<p>You're looking for <code>HttpContext.Handler</code>. Since Page implements IHttpHandler, you'll obtain a reference to the currently executing page.You'll have to cast it, or at least try to cast it to the particular type you're looking for. </p>\n\n<p><code>HttpContext.Current</code> simply returns the singleton instance of HttpContext. Therefore, it is not and can never be, a page.</p>\n"}, {'answer_id': 58131, 'author': 'Ash', 'author_id': 5023, 'author_profile': 'https://Stackoverflow.com/users/5023', 'pm_score': 8, 'selected': True, 'text': '<p>No, from MSDN on HttpContext.Current: "Gets or sets the HttpContext object for the current HTTP request."  </p>\n\n<p>In other words it is an HttpContext object, not a Page.</p>\n\n<p>You can get to the Page  object via HttpContext using:</p>\n\n<pre><code>Page page = HttpContext.Current.Handler as Page;\n\nif (page != null)\n{\n     // Use page instance.\n}\n</code></pre>\n'}, {'answer_id': 6617694, 'author': 'user452427', 'author_id': 452427, 'author_profile': 'https://Stackoverflow.com/users/452427', 'pm_score': 4, 'selected': False, 'text': '<p>You may want to use <code>HttpContext.Current.CurrentHandler</code> if you want the precise page that is currently executing. For example, a request for Default.aspx is sent, but an error is thrown and you do a <code>Response.Transfer</code> to your custom ErrorHandler.aspx page. <code>CurrentHandler</code> will return the instance of ErrorHandler.aspx (if called after the error) whereas <code>HttpContext.Current.Handler</code> would return an instance of Default.aspx.</p>\n'}, {'answer_id': 17983443, 'author': 'Amin Ghaderi', 'author_id': 1395101, 'author_profile': 'https://Stackoverflow.com/users/1395101', 'pm_score': 0, 'selected': False, 'text': '<p>Please see my answer : <br/>\n<a href="https://stackoverflow.com/questions/1054123/why-httpcontext-current-handler-is-null">Why HttpContext.Current.Handler is null?</a>\n<br/><br/>\nMaybe resolved your problem.<br/></p>\n'}]
['https://Stackoverflow.com/questions/58123', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1685/']