身份验证令牌未在IE中传递

时间:2014-01-13 12:46:38

标签: asp.net asp.net-mvc asp.net-mvc-4 jquery authentication

我正在使用asp.net mvc4应用程序。我正在使用表单身份验证。我的方案是这样的,在身份验证后,当我使用IE时,身份验证令牌没有在请求标头中传递。但它工作正常chrome和Mozilla。这是我的身份验证是在第一种方法完成的,而我调用的第二种方法是ajax调用。是不是他们遇到了ajax调用的问题?

首先验证方法是getjson方法。然后我使用ajax调用。

if (user != "" && passwd != "" && location != "" && location != -1) {
        $.getJSON(window.contexthttproot + "/Account/Location", { 'Username': user, 'Password': passwd }, function (items) {

         if (items.length > 0) {
                            $('#Serverow').hide();
                            $('#locate').show();
                            $('#location').show();


  $("#Username").attr("disabled", "disabled");
                        $("#Password").attr("disabled", "disabled");
                        $("#Location").fillSelect($.map(items, function (item) {
                            return {
                                ID: item.LocationID,
                                Name: item.LocationName
                            };
                        }));
                        setTimeout(function () {
                            $('#spinner').fadeOut('fast');
                        })
                    }
                    else {
                        setTimeout(function () {
                            $('#spinner').fadeOut('fast');

                        })

                    }
                });
            }
}


    if (user != "" && passwd != "" && location != "" && location != -1) {

                var json = "{'location':'" + location + "','locationName':'" + loctext + "'}";

                $.ajax({
                    url: window.contexthttproot + "/Report/ReportLocation",
                    type: 'POST',
                    datatype: "json",
                    contentType: "application/json; charset=utf-8",
                    cache: false,
                    data: json,
                    success: function (items) {

                        window.location.replace("/LandingPage/Landing");
                        setTimeout(function () {
                            $('#spinner').fadeOut(35000);
                        })
                    },
                    error: function (xhr, status) {

                    }

                });
            }

2 个答案:

答案 0 :(得分:0)

来源SO

IE有一个奇怪的错误 - 由于某些原因,如果域名中有非字母数字字符,IE将不会持久存在cookie ...因此,不同的调用之间你将没有持久会话。

检查您的域中是否包含非字母数字字符,例如test_domain或test-domain等。

here获得解决方案

== Workaround ==

In the meantime to make it work and to avoid similar issues in the future, I use a file ~\App_Browsers\BrowserFile.browser with the following:

<browsers>
<browser refID="Default">
<capabilities><!-- To avoid wrong detections of e.g. IE10 -->
<capability name="cookies" value="true" />
<capability name="ecmascriptversion" value="3.0" />
</capabilities>
</browser>
</browsers>

也.. 问题在于一些IIS实例认为IE10是一个无cookie的浏览器(即不支持cookie)。在我们的问题情况下,服务器正在设置身份验证cookie并将其发送回浏览器,但随后忽略了后续请求中的cookie。

解决方案是修补浏览器功能,以便它知道IE10可以执行cookie(在此页面上的另一个答案中概述),或更改默认行为以强制它使用cookie,即使它认为浏览器不能做饼干。

我们刚刚将以下内容添加到web.config中的表单部分:

无Cookie = “UseCookies”

<authentication mode="Forms">
  <forms name=".AUTH" cookieless="UseCookies" loginUrl="/" timeout="10000" path="/" />
</authentication>

答案 1 :(得分:0)

检查服务器上运行的.net版本是否适用于您的asp.net应用程序。您可能至少需要4.5。 IE 11有一些已知问题。

http://www.microsoft.com/en-us/download/details.aspx?id=30653

这是另一个类似问题的链接。

IE11 and the .NET User.Identity.IsAuthenticated always returns false