2008-10-16 26 views

उत्तर

18

कुकी सेट करें, कुछ जांच पृष्ठ पर रीडायरेक्ट को मजबूर करें और कुकी जांचें।

या प्रत्येक पगेलोड पर एक कुकी सेट करें, अगर यह पहले से सेट नहीं है। उदाहरण के लिए, मुझे लगता है कि यह जांचना है कि कुकीज़ को लॉगिन करने का प्रयास करते समय संदेश प्रदर्शित करने के लिए समर्थित हैं या नहीं, उन्हें कुकीज़ सक्षम करने की आवश्यकता है। अतिथि लॉगिन उपयोगकर्ताओं के लिए कुछ डिफ़ॉल्ट मान पर अपनी लॉगिन कुकी सेट करें यदि उनके पास अभी तक कुकी सेट नहीं है। फिर अपने लॉगिन पेज पर, उपयोगकर्ता कुकी की जांच करें, और यदि यह सेट नहीं है, तो अपना संदेश प्रदर्शित करें।

+0

आप सटीक कोड के साथ प्रदान कर सकते हैं? मैंने रीडायरेक्ट करने का प्रयास किया है। पृष्ठ को सीधे लोड करने में इसका कोई फर्क नहीं पड़ता है। कुकी अभी भी पढ़ी जा सकती है भले ही कुकी अक्षम है। –

1

एक कुकी लिखें, रीडायरेक्ट करें, देखें कि क्या आप कुकी पढ़ सकते हैं या नहीं, यह निर्धारित करने के लिए सबसे अच्छी विधि क्या है।

1

मुझे लगता है कि अगर हम ग्लोबल.एक्सएक्स सत्र में कुकी को सहेज सकते हैं और पेज पर पढ़ सकते हैं .. यह सबसे अच्छा तरीका नहीं है?

-3

इस का सबसे अच्छा तरीका

http://www.eggheadcafe.com/community/aspnet/7/42769/cookies-enabled-or-not-.aspx

function cc() 
{ 
/* check for a cookie */ 
    if (document.cookie == "") 
    { 
    /* if a cookie is not found - alert user - 
    change cookieexists field value to false */ 
    alert("COOKIES need to be enabled!"); 

    /* If the user has Cookies disabled an alert will let him know 
     that cookies need to be enabled to log on.*/ 

    document.Form1.cookieexists.value ="false" 
    } else { 
    /* this sets the value to true and nothing else will happen, 
     the user will be able to log on*/ 
    document.Form1.cookieexists.value ="true" 
    } 
} 

धन्यवाद से वेंकट कश्मीर

-1

करने के लिए लिया तुम भी Request.Browser.Cookies का मूल्य की जांच कर सकते है। यदि सही है, ब्राउज़र कुकीज़ का समर्थन करता है।

+1

ब्राउज़र। कुकीज सच है यदि ब्राउजर * कुकीज़ का समर्थन करता है, तो कुकीज अक्षम होने पर भी यह सच है: "यदि उपयोगकर्ता ने अपने आवेदन में कुकीज़ अक्षम कर दी हैं, तो कुकीज संपत्ति प्रभावित नहीं होगी।" (Http://msdn.microsoft.com/en-us/library/system.web.configuration.httpcapabilitiesbase.cookies(v=VS.90).aspx) – mamoo

3

@ मैट्यू एक कुकी सेट करने के लिए सही तरीका है, रीडायरेक्ट करें, फिर इसे जांचें।

private bool cookiesAreEnabled() 
{ 
bool cookieEnabled = false; 

if(Request.Browser.Cookies) 
{ 
    //Your Browser supports cookies 
    if (Request.QueryString["TestingCookie"] == null) 
    { 
    //not testing the cookie so create it 
    HttpCookie cookie = new HttpCookie("CookieTest",""); 
    Response.Cookies.Add(cookie); 

    //redirect to same page because the cookie will be written to the client computer, 
    //only upon sending the response back from the server 
    Response.Redirect("Default.aspx?TestingCookie=1") 
    } 
    else 
    { 
    //let's check if Cookies are enabled 
     if(Request.Cookies["CookieTest"] == null) 
     { 
     //Cookies are disabled 
     } 
     else 
     { 
     //Cookies are enabled 
     cookieEnabled = true; 
     } 
    } 

} 
else 
{ 
    // Your Browser does not support cookies 
} 
return cookieEnabled; 
} 


तुम भी जावास्क्रिप्ट, इस तरह से यह कर सकते हैं:

function cookiesAreEnabled() 
{ 
    var cookieEnabled = (navigator.cookieEnabled) ? 1 : 0; 

    if (typeof navigator.cookieEnabled == "undefined" && cookieEnabled == 0){ 
    document.cookie="testcookie"; 
    cookieEnabled = (document.cookie.indexOf("test­cookie") != -1) ? 1 : 0; 
    } 

    return cookieEnabled == 1; 
} 
0

Meda के ग # समारोह यहाँ कि देखें कि आपको अपने पेज लोड घटना में इस डाल सकते हैं पहिले करने के लिए एक सी # समारोह है काम करता है हालांकि आपको लाइन को बदलना है:

एचटीपीकुकी कुकी = नया एचटीपी कूकी ("", "");

को HttpCookie कुकी = नए HttpCookie ("CookieTest", "CookieTest");

0

मूलतः Meda रूप में एक ही समाधान है, लेकिन VB.NET में:

Private Function IsCookieDisabled() As Boolean 
    Dim currentUrl As String = Request.RawUrl 
    If Request.Browser.Cookies Then 
     'Your Browser supports cookies 
     If Request.QueryString("cc") Is Nothing Then 
      'not testing the cookie so create it 
      Dim c As HttpCookie = New HttpCookie("SupportCookies", "true") 
      Response.Cookies.Add(c) 
      If currentUrl.IndexOf("?") > 0 Then 
       currentUrl = currentUrl + "&cc=true" 
      Else 
       currentUrl = currentUrl + "?cc=true" 
      End If 
      Response.Redirect(currentUrl) 
     Else 
      'let's check if Cookies are enabled 
      If Request.Cookies("SupportCookies") Is Nothing Then 
       'Cookies are disabled 
       Return True 
      Else 
       'Cookies are enabled 
       Return False 
      End If 
     End If 
    Else 
     Return True 
    End If 
End Function 
संबंधित मुद्दे

 संबंधित मुद्दे