0

I want to set cookies for a specific domain to fetch data in English version in C# while crawling the website. Suppose a website www.xyz.com has four language version including English. The actual data in database are in any other language (suppose Swedish). While crawling the site to get all of its links and text, need to fetch the contents of English version. That's why I want to set cookies there. But it's not working. Please check the piece of code below to set cookie for English version.

if (_domain == "www.xyz.com")
{
    HttpCookie CreateLangCookie()
    {
        HttpCookie cookie = new HttpCookie("Cookies");
        cookie.Name = "lang";
        cookie.Value = "en";
        cookie.Domain = ".xyz.com";
        cookie.Path = "/";
        cookie.Expires = DateTime.MaxValue;
        return cookie;
    }
    Response.Cookies.Add(CreateLangCookie());
}
Soheila Tarighi
  • 487
  • 4
  • 15
Routh
  • 41
  • 7

1 Answers1

0

You might want to expand your question to note what you mean by "not working" and to include what browser you are using, but the solution might be to not use explicit cookies, as explained in this answer: Cookies with and without the Domain Specified (browser inconsistency)

Tom Regan
  • 3,580
  • 4
  • 42
  • 71
  • Thanks for your reply sir. I am going to make a crawler for a website which is in Swedish language by default and having several language versions, those which can be change from the front-end. To get English contents from the English version of that website i set cookies (* please check the code above) but still it is returning contents on Swedish language. Although i have checked my cookie is saved correctly. – Routh Apr 08 '20 at 06:44