Cookie Port Settings

I am trying to set the port in a cookie in ASP.NET (code below), but at runtime (below code) I get a very unusual error. Any thoughts?

target.Cookie = new Cookie
{
    Comment = "Test Comment",
    CommentUri = new System.Uri("http://www.tempuri.org"),
    Discard = false,
    Domain = "tempuri.com",
    Expired = false,
    Expires = new DateTime(2015, 12, 31),
    HttpOnly = false,
    Name = "TestCookie",
    Path = "/",
    Port = "443",
    Secure = false,
    Value = "Test Value",
    Version = 1,
};

An exception:

System.Net.CookieException: The 'Port'='443' part of the cookie is invalid..

Edit: Sorry, I meant that I also tried Port = "80" without success.

+3
source share
3 answers

Unfortunately, I have not found a good solution. All I did was delete the port definition. I noticed something in the W3C specification for cookies regarding ports, and if I recall, version 2 cookies do not support the port specification. I tried to create a cookie without a port, and then set the port later, but no luck. I keep getting runtime exception...threw exception: System.Net.CookieException: The 'Port'='80' part of the cookie is invalid..

, ...

+1

443 SSL, Secure false. 443, Secure = true.

+1

A bit late, I know, but ran into a similar problem, and the ports should be set in double quotes with comma delimited ones.

port = @"""80,8080"""

"... Otherwise, the value must be a double-quoted string that contains port values ​​separated by commas."

MSDN docs for port property

0
source

Source: https://habr.com/ru/post/1736046/


All Articles