[CLOSED] Globally Stop Execution of Direct Methods when Session is Expired

  1. #1

    [CLOSED] Globally Stop Execution of Direct Methods when Session is Expired

    I know we need to use the Ext.net.X.Redirect when session is expired during a ajax request, but even after we call this method the execution of the direct method still occurs. This can cause an error when we are accessing Session during the direct method call. I am wondering if we can globally stop the execution of the ajax request to prevent this from happening. We could check for the Session variable being null in the direct method, but we would rather not have to go back and add this check to hundreds of existing direct methods.

    Thanks!
    Last edited by geoffrey.mcgill; Jan 26, 2012 at 5:24 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Vladimir suggests to try with Global.asax by the following way:

    Example
    protected void Application_PostAcquireRequestState(object sender, EventArgs e)
    {
        HttpApplication app = (HttpApplication)sender;
        HttpRequest request = app.Context.Request;
    
        if (X.IsAjaxRequest && app.Session.IsNewSession)
        {
            app.Context.Response.Clear();
            app.Context.Response.ClearContent();
            app.Context.Response.ClearHeaders();
            app.Context.Response.StatusCode = 200;
            app.Context.Response.ContentType = "application/json";
            app.Context.Response.Charset = "utf-8";
            app.Context.Response.Cache.SetNoServerCaching();
            app.Context.Response.Cache.SetMaxAge(TimeSpan.Zero);
    
            app.Context.Response.Write(string.Format("{{script:\"window.location='login.aspx';\"}}"));
            app.CompleteRequest();
        }
    }
  3. #3
    Thanks guys. This works well in most situations. However, it does appear that sometimes when clicking on a TabPanel that loads another page in an iframe, the page in the iframe continues to execute. So an exception is thrown. The exception does not prevent the redirect though, so not a huge issue. I guess it could cause confusion for exception logging purposes.

    I thought I'd mention it to see if you guys have any ideas?

    Thanks!
  4. #4
    Correction:
    The issue comes from clicking on a Panel in a TabPanel collection.

    Here are some properties we set when creating the panel:
    int userFormId = 1;
    Ext.Net.Panel tab = new Ext.Net.Panel();
    tab.Closable = true;
    tab.Border = false;
    tab.Title = "My Panel";
    tab.TabTip = "This is my panel";
    tab.AutoLoad.Url = "PathToWebContentPage.aspx";
    tab.AutoLoad.Mode = Ext.Net.LoadMode.IFrame;
    tab.AutoLoad.MaskMsg = "Loading...";
    tab.AutoLoad.ShowMask = true;
    tab.ID = string.Format("tab_{0}", userFormId);
    tab.Listeners.Close.Handler = string.Format("Ext.net.DirectMethods.CloseForm('{0}')", userFormId);
    tab.Listeners.Activate.Handler = string.Format("Ext.net.DirectMethods.ActivateTab('{0}')", userFormId);
    tab.Icon = Ext.Net.Icon.Page;
    tab.CustomConfig.Add(new ConfigItem("userFormId", userFormId.ToString()));
     
    //The TabPanel
    TabPanel1.Items.Add(tab);
    The exception occurs during the page load of the page in the iframe and not during the Activate handler call. So it appears that the direct method execution was stopped as we wanted, but the iframe autoloading is not stopped.

    Thanks!
  5. #5
    Well, there is no direct relation between iframe and AJAX.

    You should be able to pass a respective parameter within an url and analyze it in Global.asax.

    You should return 302 status code in a case with an iframe.

    As well Response.Redirect might work (not 100% sure). Though redirection will occur within an iframe.

    Probably, you will need to redirect a parent page. Then you should return a page, i.e. a correct HTML page with:
    parent.window.location = "url";
    script.

    Don't forget to set up "text/html" ContentType.
    Last edited by Daniil; Jan 22, 2012 at 4:16 PM.

Similar Threads

  1. Direct Methods and Custom Control
    By Zdenek in forum 1.x Help
    Replies: 0
    Last Post: Apr 19, 2012, 10:18 PM
  2. [CLOSED] Session expired into iframe
    By stoque in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jan 11, 2012, 6:24 PM
  3. [CLOSED] Common Direct Methods
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Nov 25, 2011, 5:54 AM
  4. Are direct methods same as WebMethod
    By deeptechtons in forum 1.x Help
    Replies: 2
    Last Post: Dec 27, 2010, 3:31 AM
  5. [CLOSED] MessageBox: stop execution until message box button is clicked
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Aug 06, 2010, 2:24 PM

Posting Permissions