System.Web.HttpException: Response is not available in this context

9 posts, 0 answers
  1. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 02 Sep 2009 Link to this post

    Hello,

    I get this after an exception in an ajax callback (using RadAjaxManager) when I try to redirect to an error page using
    Ajax redirect.
    My code
                if ( IsInAsyncPostBack && ( AjaxManager != null ) )  
                {  
                    if ( url.StartsWith("~/") )  
                        url     =   ResolveClientUrl(url);  
                    AjaxManager.Redirect(url);  
                }  
                else  
                    Response.Redirect(url,endResponse);  
     

    May be ajaxmanager should not get Page.Response but HttpContext.Current.Response ?

    May be the idea of redirecting using ajax during a call back is bad ?
    In this case how to incorporate ajax in my general errors manager which redirects to a standard error page.


    Thanks for help
    CS
  2. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 03 Sep 2009 Link to this post

    Hi,

    Here is described how to redirect to another page with ajax:
    http://www.telerik.com/help/aspnet-ajax/ajxredirectingtoanotherpage.html

    And for custom error redirection, you can try setting the AllowCustomErrorsRedirect property of the ScriptManager and see how it works:
    <asp:ScriptManager ID="ScriptManager1" runat="server" AllowCustomErrorsRedirect="true" /> 




    Additionally, can you confirm that the code in the if statement is executed, not only this in the else block?

    Regards,
    SamJ
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 03 Sep 2009 Link to this post

    Thanks, but I know this, I am using it regularly due to IIS7 pb with Ajax.
    The effect of my code is to detect erro occuring inside a call back and to try using Ajax redirect...but the concept seems to have been shorten somewhere before completion, certainly lack of time, very common usage nowdays....

    Yes I confirm that the exception occurs in RadAjaxManager, stack trace identity it as caller.

    CS
  5. SamJ
    SamJ avatar
    101 posts
    Member since:
    Jul 2008

    Posted 03 Sep 2009 Link to this post

    Hi Christian,

    In this case I assume you can try to handle the errors following the suggestions here:
    http://www.telerik.com/help/aspnet-ajax/ajxerrorhandling.html

    Does this work for you?

    Thanks,
    SamJ



  6. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 03 Sep 2009 Link to this post

    Thanks again,

    Have you been there ?
    when clicking on <customErrors> Element we get
    http://msdn.microsoft.com/en-us/library/y123fsf7.aspx

    and that's final story :)

    More seriously, this process doesn't comply with my own error flow....
    I would prefer Telerik not doing an access to Page property attached to scriptmanager or ajaxmanager to get Response because it is no more available at the stage I need it.
    Using HttpContext.Current could work.

    It could be a telerik bug .


    CS
  7. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 08 Sep 2009 Link to this post

    Hi Christian,

    Would you please provide us more information on your scenario and what is the desired by you functionality that can not be implemented using the RadAjaxManager?

    I am looking forward to your reply.

    Regards,
    Mira
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 08 Sep 2009 Link to this post

    Hello Mira,

    In my error scenario, all exceptions are trapped as soon as possible and transformed in a generic app exeption depending on context, then these exceptions are catched by the general app error handler in Global.asax, here after some analysis the response is redirected to different error pages.

    When the error occurs in a postback, no pb everything works.
    When error occurs during an ajax callback, I was expecting to be able to redirect from clientside using ajaxmanager redirect, but it appears that code in ajaxmanager uses the Page property to access Response.
    This doesn't work because Page.Response is no more accessible (I get an exception and see from the exception stack it occurs in ajaxmanager trying to access Page.Response), it should use HttpContext.Response because it seems to be available even when Page.response is no more accessible.


    Regards
    CS
  9. CSurieux
    CSurieux avatar
    465 posts
    Member since:
    Jan 2007

    Posted 09 Sep 2009 Link to this post

    Mira,

     To be more factual, here is the stack trace on exception catching:
    [E]ErrorHandler ProcessUnhandledException Unexpected error, ex3 : System.Web.HttpException: Response is not available in this context.
       at System.Web.UI.Page.get_Response()
       at Telerik.Web.UI.RadAjaxControl.Redirect(String location)
    ....

    May this help you correcting.

    Regards
    CS
  10. Mira
    Admin
    Mira avatar
    1124 posts

    Posted 10 Sep 2009 Link to this post

    Hi Christian,

    Unfortunately I am still unable to find out what is the issue.

    Would please tell me what in the approach for Redirecting to another page and Error Handling For Ajax Requests does not work for your scenario?


    Kind regards,
    Mira
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017