Hack Forums
[.NET] Recreate CookieContainer Issue (Loading from Textfile) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Recreate CookieContainer Issue (Loading from Textfile) (/showthread.php?tid=5997144)



Recreate CookieContainer Issue (Loading from Textfile) - MalwareMop - Aug 7, 2019

Thread closed. I have figured it out.

The issue if anyone ever has the problem themselves is that specifying a "Domain" is automatically registered as a sub-domain. To add to the parent site you must specify a URI instead. Here's how I fixed it.

Code
Public Shared Function ReturnLoginSession(ByVal Form As FrmMain, ByVal Profile As String) As CookieContainer
        For Each LoginSession As LoginSession In LoginSessionList
            If LoginSession.Profile.ToLower.Equals(Profile) Then
                Dim CookieContainer As New CookieContainer
                For Each Cookie As Cookie In LoginSession.Cookies
                    If Not Cookie.Domain.StartsWith("."c) Then
                        Dim NewCookieContainer As New CookieContainer()
                        Dim NewCookies As New Cookie()
                        With NewCookies
                            .Name = Cookie.Name
                            .Version = Cookie.Version
                            .Comment = Cookie.Comment
                            .CommentUri = Cookie.CommentUri
                            .Discard = Cookie.Discard
                            .Expired = Cookie.Expired
                            .Expires = Cookie.Expires
                            .HttpOnly = Cookie.HttpOnly
                            .Path = Cookie.Path
                            .Port = Cookie.Port
                            .Secure = Cookie.Secure
                            .Value = Cookie.Value
                        End With
                        CookieContainer.Add(New Uri(String.Format("http://{0}", Cookie.Domain)), NewCookies)
                    Else
                        CookieContainer.Add(Cookie)
                    End If
                Next
                Form.AppendTextBoxText(Form.TxtChat, String.Format("Setting saved session for account: {0}...", Profile))
                Return CookieContainer
            End If
        Next
        Return New CookieContainer
    End Function

Hope this helps.