Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Cookie Port

I'm trying to set the port on a cookie in ASP.NET (code below), but I'm getting a very unusual error at runtime (below the code). 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,
};

Exception:

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

Edit: Sorry, I meant to mention that I also tried Port = "80" with no success.

like image 815
CodeMonkey1313 Avatar asked Apr 13 '26 07:04

CodeMonkey1313


1 Answers

Bit late I know but ran into a similar issue and the Ports must be set within comma delimited double quotes.

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

"...the value must be a double-quoted string that contains port values delimited with commas." .Net Documentation for the Port Property:

like image 86
OraDotNetDev Avatar answered Apr 14 '26 23:04

OraDotNetDev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!