[CLOSED] Window() failureHandler to catch unauthorized load url call

  1. #1

    [CLOSED] Window() failureHandler to catch unauthorized load url call

    I have a window:

    @(Html.X().Window()
            .ID("EditSalesRecordWindow")
            .Icon(Icon.ApplicationViewDetail)
            .Hidden(true)
            .Height(600)
            .Width(1000)
            .Layout(LayoutType.Fit)
            .Loader(Html.X().ComponentLoader()
                .AutoLoad(false)
                .Failure("failureHandlerfunction")
                .Mode(LoadMode.Html)
                .Scripts(true)
                .LoadMask(mask => mask.ShowMask = true)
                .Params(new
                {
                    containerId = "EditSalesRecordWindow"
                })
            )
        )
    And a function that calls this window and loads a url into it:

    var openEditCustomerWindow = function (recordId, title, callurl) {
        App.EditSalesRecordWindow.removeAll();
        App.EditSalesRecordWindow.setTitle(title);
        App.EditSalesRecordWindow.show();
        App.EditSalesRecordWindow.load({
            url: callurl,
            params: {
                id: recordId
            }        
        });
        App.EditSalesRecordWindow.failureHandler("failureHandlerfunction");
    };
    
    
    var failureHandlerfunction = function (error, response) {
        if (response.status == 401) {
                    Ext.Msg.alert('Error', response.statusText);
       }
       if (response.status == 416) {
                    Ext.Msg.alert('Error', response.statusText);
       }
    };
    When the session is expired, this call to load a url should be caught by the failureHandler function. But it is not.
    From another controller method I return:

    Request.RequestContext.HttpContext.Response.StatusCode = 416;
                return this.Direct();
    And this is caught by the failureHandler function.
    But the unauthorized is not.

    Please help.
    Last edited by Daniil; Mar 20, 2015 at 11:52 AM. Reason: [CLOSED]
  2. #2
    Hello registrator,

    I think the answer in the following thread:
    http://forums.ext.net/showthread.php...ed-method-call

    applies, doesn't it?
  3. #3
    It does... in general, yes.
    I was actually looking for something different this time. I am not sure if this is possible at all.
    What I did to solve this is this:

    Create a custom Authorize attribute:

    public class AjaxAuthorizeAttribute : AuthorizeAttribute
        {
            protected override void HandleUnauthorizedRequest(AuthorizationContext context)
            {
                var urlHelper = new UrlHelper(context.RequestContext);
                context.HttpContext.Response.StatusCode = 401;
                context.Result = new DirectResult
                {
                    ErrorMessage = "Unauthorized",
                    Result = "Account/Login"
                };
            }
        }
    Handle the Success event of window load:

    var openEditCustomerWindow = function (recordId, title, callurl) {
        App.EditSalesRecordWindow.removeAll();
        App.EditSalesRecordWindow.setTitle(title);
        App.EditSalesRecordWindow.show();
        App.EditSalesRecordWindow.load({
            url: callurl,
            params: {
                id: recordId
            },
            success: function (result) {
                if (result.responseText == '{"success":false,"errorMessage":"Unauthorized","result":"Account/Login"}') {
                    App.EditSalesRecordWindow.hide();
                    window.location.href = 'Account/Login';
                };
            },
        });
        App.EditSalesRecordWindow.failureHandler("failureHandlerfunction");    
    };
    I still have the failure handler to handle some of my custom return values.
    It's the dirty solution but I couldn't find anything better at this time.
    If you have a suggestion please post it. Otherwise close this thread.
    Thank you

Similar Threads

  1. [CLOSED] MultiUpload with Firefox - Unauthorized
    By ViDom in forum 2.x Legacy Premium Help
    Replies: 7
    Last Post: Jul 28, 2014, 7:18 AM
  2. window.eval.call(window,result.script error
    By khalidal in forum 2.x Help
    Replies: 0
    Last Post: Jan 15, 2014, 3:11 PM
  3. [CLOSED] call renderer from store load
    By Z in forum 1.x Legacy Premium Help
    Replies: 9
    Last Post: Oct 14, 2013, 12:33 AM
  4. Show a load mask with a DirectMethod call
    By ashwinrath in forum 1.x Help
    Replies: 2
    Last Post: Apr 21, 2012, 6:35 PM
  5. Replies: 6
    Last Post: Feb 15, 2012, 4:15 PM

Posting Permissions