如何与Angular 12应用程序共享ASP.NET Cookie
如何与Angular 12应用程序共享ASP.NET Cookie?
我在ASP.NET应用程序中有以下代码来创建Cookie:
HttpCookie cookie = new HttpCookie(".AspNet.SharedCookie", DateTime.Now.ToString())
{
Expires = DateTime.Now.AddHours(24),
Secure = true,
Domain = "localhost",
Path = "/",
};
HttpContext.Response.Cookies.Add(cookie);
return Content("Welcome, new visitor!");
我正在尝试在Angular 12应用程序中阅读此Cookie。
这是我的代码:
import { CookieService } from '../../../../node_modules/ngx-cookie-service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(private cookieService: CookieService) { }
cookieValue: string = "";
ngOnInit(): void {
debugger;
this.cookieValue = this.cookieService.get('.AspNet.SharedCookie');
console.log(this.cookieService.get('.AspNet.SharedCookie'));
}
}
我总是把Cookievalue作为空?
How to share Asp.net cookie with Angular 12 application?
I have the following code in my ASP.NET application to create cookie:
HttpCookie cookie = new HttpCookie(".AspNet.SharedCookie", DateTime.Now.ToString())
{
Expires = DateTime.Now.AddHours(24),
Secure = true,
Domain = "localhost",
Path = "/",
};
HttpContext.Response.Cookies.Add(cookie);
return Content("Welcome, new visitor!");
I am trying to read this cookie in Angular 12 application.
This is my code:
import { CookieService } from '../../../../node_modules/ngx-cookie-service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor(private cookieService: CookieService) { }
cookieValue: string = "";
ngOnInit(): void {
debugger;
this.cookieValue = this.cookieService.get('.AspNet.SharedCookie');
console.log(this.cookieService.get('.AspNet.SharedCookie'));
}
}
I am always getting cookieValue as empty?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论