In what area should I give this cookie?

I am trying to call a web service from a C # application with sessionID.
To do this, I need to set the "Domain" header in the cookie.

In Fiddler, it looks like "ASP.NET_SessionId = izdtd4tbzczsa3nlt5ujrbf5" (the domain is not specified in the cookie).

The web service is located in the folder "http: // [some ip goes here]: 8989 / MyAPI.asmx".

I tried:
http: // [ip],
http: // [ip]: 8989,
http: // [ip]: 8989 / MyAPI.asmx

All this causes a runtime error.

I also tried only the ip address (i.e. 100.10.10.10), which does not cause a runtime error, and sets a cookie, but the cookie is never sent when I call the website method.

Here is my code for setting up the domain:

if (!string.IsNullOrEmpty(currentSessionID))
{
   req.CookieContainer=new CookieContainer();
   Cookie cookie = new Cookie("ASP.NET_SessionId", currentSessionID);
   cookie.Domain = GetCookieUrl();  //<- What should this be?
   req.CookieContainer.Add(cookie);
}

?

.

+3
3

, cookie , , ​​ , cookie, .
- ip.

0

, [ip]. http://, .

MSDN,

cookie.Domain = "100.10.10.10";

, ? , Runtime? , , Domain String, , - .

, cookie -? - .


BTW, cookie , -, , , ( ):

byte[] buffer = Encoding.ASCII.GetBytes("fareId=123456"); //the data you want to send to the web service
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
WebReq.Method = "POST";
WebReq.ContentType = "application/x-www-form-urlencoded";
WebReq.ContentLength = buffer.Length;
WebReq.Headers["Cookie"] = "ASP.NET_SessionId=izdtd4tbzczsa3nlt5ujrbf5"

Stream PostData = WebReq.GetRequestStream();

, inline "cookie". Domain cookie , cookie . , , - .

+1
// Simple function to get cookie domain
private string GetCookieDomain(string uri)
{
    Uri req_uri = new Uri(uri);
    return req_uri.GetComponents(UriComponents.Host, UriFormat.Unescaped);
}
0
source

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


All Articles