2014-01-13 180 views
0

我正在使用asp.net mvc4 application.Here我使用表單身份驗證。我的情況是這樣的,身份驗證後身份驗證令牌沒有傳遞請求頭時,我使用IE但它在Chrome和Mozilla中運行正常。在這裏我的身份驗證是在第一種方法中完成的,而我所調用的第二種方法是ajax調用。是否有任何與ajax調用有關的問題?身份驗證令牌未通過IE

第一種驗證方法是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) { 

        } 

       }); 
      } 
+0

什麼版本的IE? –

+0

看看這個http://stackoverflow.com/questions/19725827/internet-explorer-11-session-issue-with-asp-net-4-0 –

+0

@Pjack使用IE 11. – Sajeev

回答

0

源,以便

IE從一個奇怪的錯誤遭受 - 因爲某些原因,如果在域的名稱非字母數字字符,IE不會存留餅乾......,因此你會不同呼叫之間沒有持續會話。

檢查您的域中是否包含非字母數字字符,如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的瀏覽器(即傾斜支持Cookies)。在我們的問題案例中,服務器設置了身份驗證cookie並將其發送回瀏覽器,但隨後忽略了cookie。

解決方案是修補瀏覽器功能,以便它知道IE10可以執行cookie(在本頁的另一個答案中概述),或者更改默認行爲以強制它使用cookie,即使它認爲瀏覽器可以'不要做餅乾。

我們剛剛添加以下到我們的表格節在web.config中:

無Cookie =「UseCookies」

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

我的域名不包含任何特殊符號。當我降級我的瀏覽器到ie 9它的工作很好。可以建議任何想法來解決這個 – Sajeev

+0

@Sajeev檢查編輯答案它是從我的回答中發佈的鏈接 – Nilesh

+0

我已經在我的asp.net mvc應用程序中嘗試了上述方法。但它對我的第一次登錄很有效。在我第二次登錄時,驗證cookie不會發送到請求標頭 – Sajeev