在我的网站中,我正在使用表单身份验证。我想为此目的进行网络请求,我正在使用cookieContainer的帮助。我的代码是这样的
string url = HttpContext.Current.Request.Url.AbsoluteUri;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
HttpCookie cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
Cookie authenticationCookie = new Cookie(
FormsAuthentication.FormsCookieName,
cookie.Value,
cookie.Path,
HttpContext.Current.Request.Url.Authority);
req.CookieContainer = new CookieContainer();
req.CookieContainer.Add(authenticationCookie);
WebResponse res = req.GetResponse();
但是此代码会引发错误“ cookie的'Domain'='localhost:300'部分无效。 ”。因此我发现错误来自这行代码
Cookie authenticationCookie = new Cookie(
FormsAuthentication.FormsCookieName,
cookie.Value,
cookie.Path,
HttpContext.Current.Request.Url.Authority);
该站点的 url 是 localhost:300。我找不到任何解决方案。谁能告诉我出了什么问题?