[CLOSED] Handling Un-Authenticated Ajax calls [401 Error]

  1. #1

    [CLOSED] Handling Un-Authenticated Ajax calls [401 Error]

    hi,

    I'm using forms Authentication with heavy use of Json Asmx webservices and Static DirectMethods. if the user session expired and static directMethod invoked by user action the system redirect him to login page. but if the request done through Asmx webmethod the nice error window shows:

    Status Code: 401
    Status Text: Unauthorized
    {"Message":"Authentication failed.","StackTrace":null,"ExceptionType":"System .InvalidOperationException"}


    so the directMethod handle the problem correctly by redirecting the user.. now all WHAT i want is to make all ajax calls behave the same way [perform redirection] when the user session expire!

    it's clear that no code sample is needed because the solution already handled in some part in ext.net but i couldn't figure it out + i'm using MySQL custom provider and custom security tables so full project need to be posted....just i can't do that [i need like 10 hours to prepare that!!!]

    so again in other words: how-to-manage-a-redirect-request-after-a-ajax-call [i.e, store reload/load through asmx],

    refs:
    http://stackoverflow.com/questions/1...uery-ajax-call
    http://stackoverflow.com/questions/6...n-an-ajax-call

    in the above refs they adviced to do window.location... but i think the way ext.net doing is better because in this post:

    http://forums.ext.net/showthread.php...Authentication

    vladimir said
    Redirect is generated by ASP.NET, we just convert it to script for correct handling by DirectEvent client side class
    so please help me ASAP!
    Last edited by Daniil; May 02, 2011 at 10:30 AM. Reason: [CLOSED]
  2. #2
    Hi,

    I suggest to add Failure handler to a direct event
    Failure="if(response.status == 401){window.location = 'login.aspx';}"
  3. #3
    Hi,

    Or may be it is better to add it to ResourceManager
     <ext:ResourceManager runat="server">
                <Listeners>
                    <AjaxRequestException Handler="if(response.status == 401){window.location = 'login.aspx';}" />
                </Listeners>
            </ext:ResourceManager>
  4. #4
    thanks dude, can i add that to web.config or global place! if yes then how?

    thanks,
  5. #5
    Hi,

    There is no such option in web.config.

    You could add it manually into Ext.Net sources.

    1. Please find Ext.onReady() script in
    <Ext.Net SNV folder>\Ext.Net\Build\Ext.Net\extnet\core\init\End .js

    2. Add the following script:
    Ext.onReady(function() {
        //existing code
        
        Ext.net.DirectEvent.on({
            ajaxrequestexception : {
                fn : function (response,result,el,eventType,action,extraParams,o){
                        if (response.status == 401) {
                            window.location = 'login.aspx';
                        }
                     }
            }
        });
    });
    3. Build Ext.Net scripts
    <Ext.Net SNV folder>\Ext.Net\Build\Ext.Net\extnet\build.bat

    4. Rebuild the Ext.Net solution.

Similar Threads

  1. [CLOSED] Handling only Ajax Communication Errors
    By sbg in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 13, 2012, 10:30 AM
  2. Single mask for all ajax calls
    By huzzy143 in forum 1.x Help
    Replies: 3
    Last Post: Jan 24, 2012, 6:37 PM
  3. Sequential ajax calls
    By costab in forum 1.x Help
    Replies: 1
    Last Post: May 21, 2011, 11:51 AM
  4. Replies: 15
    Last Post: Feb 03, 2011, 1:27 PM
  5. [CLOSED] Ajax File Download - Handling an Error
    By rcaunt in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Apr 12, 2010, 10:01 AM

Tags for this Thread

Posting Permissions