Why does the 'as' keyword work while the () cast does not
<pre><code>//always works, returning a valid object into _page
        _page = _httpContext.Handler as System.Web.UI.Page;

//Fails throwing the exception : Unable to cast object of type 'System.Web.DefaultHttpHandler' to type 'System.Web.UI.Page'
        _page = (System.Web.UI.Page)_httpContext.Handler;
</code></pre>

<p>I would like to know why this happens?</p>

<p>EDIT:</p>

<pre><code>                //Fixes the problem
            if(_httpContext.Handler is System.Web.UI.Page)
            _page = (System.Web.UI.Page)_httpContext.Handler;
</code></pre>

<p>If i debug the 'as' keyword statement, i never get a null reference (object always assigned properly). However the () cast creates exceptions unless it has the if statment. </p>

<p>EDIT: After about 15 runs through the class i was able to get a null. Seems like it took more runs to find a null compared to how fast the () cast would catch an exception.</p>

<p>OLD: When there is a debug at the 'as' statement every time the class runs the break point hits - never null.</p>

<p>When tthere is a debug in the '()' statement within the if,  every time the break point hits the cast works properly. Werid</p>
