MS Edge handles 401 errors thus bypassing my error handler

十年热恋 提交于 2019-12-24 08:41:33

问题


I have code to make ajax calls to my web service in javascript as follows:

    $.ajax(
        {
            url: url,
            data: json,
            type: "POST",
            processData: false,
            contentType: "application/json",
            timeout: 10000,
            dataType: "text",
            global: false,
            success: function (result, jqXHR)
            {
                sccParams = {
                    result: result,
                    jqXHR: jqXHR,
                }
                successResult(sccParams)
            },
            error: function (jqXHR, textStatus, errorThrown)
            {
                errParams = {
                    jqXHR: jqXHR,
                    textStatus: textStatus,
                    errorThrown: errorThrown,
                }
                errorHandler(errParams);
            }
        });

This works fine except if there is a 401 error in MS Edge. In this case I can see that the Ajax call is fired but then it looks as if MS Edge jumps in and handles the error and neither my success or error functions are called. My errorHandler has code to handle 401 errors but this never gets to run, instead I see the following in the console logs:

HTTP401: DENIED - The requested resource requires user authentication.
(XHR)POST - https://www.mywebsite.co.uk/WebService.svc/MyWebServiceRoutine

My webservice is hosted in azure and uses aspnet_Membership.

How can I get MS Edge to back off and let me handle my own errors? Other browsers work fine.


回答1:


The cause of this appears to be that, to check for an internet connection, my code made a call to an http site. Because my site is an https site this behaviour was deemed suspicious by MS Edge. So whenever I subsequently tried to access my web service MS Edge stepped in and denied my site access.

I've replaced the call to an http site with one to an https site and all now works fine.



来源:https://stackoverflow.com/questions/44926389/ms-edge-handles-401-errors-thus-bypassing-my-error-handler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!