I am trying to implement a modification on my DNN install that will allow me to tell the end user that their cookies are blocked. I have come up with something, but it is reading the cookie no matter if cookies are blocked or not. :( At first, I was trying with my local install, but realizing that my local install is "trusted", I put this on a deployed install and it still reads the cookies when they are disabled.
Here is what I have done in the Page_Load event of the Signin.ascx.vb file:
'********************************************************************************************'
' BEGIN DNN MODIFICATION
'--------------------------------------------------------------------------------------------'
MyNamespace.Utilities.Cookies.SetCookie("PageLoad", "True")
MyNamespace.Common.Mail.SendMailToAdmin("PageLoad Cookie Equals...", String.Format("PageLoad = {0}", MyNamespace.Utilities.Cookies.GetCookieValue("PageLoad")))
If String.IsNullOrEmpty(MyNamespace.Utilities.Cookies.GetCookieValue("PageLoad")) Then
DotNetNuke.UI.Skins.Skin.AddPageMessage(Me.Page, _
Localization.GetString("ErrorMessage.CookiesDisabled.Header", Me.LocalResourceFile), _
Localization.GetString("ErrorMessage.CookiesDisabled.Text", Me.LocalResourceFile), _
ModuleMessageType.RedError)
Else
If Not String.Equals(MyNamespace.Utilities.Cookies.GetCookieValue("PageLoad"), "True") Then
DotNetNuke.UI.Skins.Skin.AddPageMessage(Me.Page, _
Localization.GetString("ErrorMessage.CookiesDisabled.Header", Me.LocalResourceFile), _
Localization.GetString("ErrorMessage.CookiesDisabled.Text", Me.LocalResourceFile), _
ModuleMessageType.RedError)
End If
End If
MyNamespace.Utilities.Cookies.SetCookie("PageLoad", "False")
'--------------------------------------------------------------------------------------------'
' END DNN MODIFICATION
'********************************************************************************************'
I have also tried setting the cookie on the home page first (Default.aspx.vb), and then checking it here (signin.ascx.vb), but the cookie is read no matter what I do. :(
The MyNamespace.Utilities.Cookies methods are as follows:
Public Shared Sub SetCookie(ByVal key As String, ByVal Value As String)
'Encode Part
key = HttpContext.Current.Server.UrlEncode(key)
Value = HttpContext.Current.Server.UrlEncode(Value)
Dim cookie As HttpCookie
cookie = New HttpCookie(key, Value)
SetCookie(cookie)
End Sub
Public Shared Function GetCookie(ByVal key As String) As HttpCookie
'encode key for retrieval
key = HttpContext.Current.Server.UrlEncode(key)
Return HttpContext.Current.Request.Cookies.Get(key)
End Function
Public Shared Function GetCookieValue(ByVal key As String) As String
Try
'don't encode key for retrieval here
'done in the GetCookie function
'get value
Dim value As String
value = GetCookie(key).Value
'decode stored value
value = HttpContext.Current.Server.UrlDecode(value)
Return value
Catch ex As Exception
Return String.Empty
End Try
End Function
Can anyone tell me why my cookie value is read even when I disable cookies? Does anyone have a better way of doing this?