.net / Sitecore - 无法在localhost上使用域名

时间:2018-01-28 20:37:13

标签: asp.net asp.net-mvc http cookies sitecore

我已尝试过其他帖子关于此问题的解决方案,但我仍无法让它发挥作用。

我只是想在服务器的响应中添加cookie。在localhost上运行的普通.net MVC解决方案:这很好用:

Response.Cookies.Add(new HttpCookie("cartId", "3")
            {
                Expires = DateTime.Now.AddMonths(12)
            });

我有一个这样的显式域名:127.0.0.1 SitecoreTestProject.com

我从Controller Action尝试了以下代码:

Response.Cookies.Add(new HttpCookie("hello", "world")
        {
            Expires = DateTime.Now.AddMonths(12)
        });
        Response.Cookies.Add(new HttpCookie("hello2", "world2")
        {
            Expires = DateTime.Now.AddMonths(12),
            Domain = "sitecoretestproject.com"
        });
        Response.Cookies.Add(new HttpCookie("hello3", "world3")
        {
            Expires = DateTime.Now.AddMonths(12),
            Domain = ".sitecoretestproject.com"
        });
        Response.Cookies.Add(new HttpCookie("hello4", "world4")
        {
            Expires = DateTime.Now.AddMonths(12),
            Domain = "localhost"
        });
        Response.Cookies.Add(new HttpCookie("hello5", "world5")
        {
            Expires = DateTime.Now.AddMonths(12),
            Domain = ".localhost"
        });
        Response.Cookies.Add(new HttpCookie("hello6", "world6")
        {
            Expires = DateTime.Now.AddMonths(12),
            Domain = null
        });

感谢任何帮助

0 个答案:

没有答案