0

次のようなCookieパスを設定しようとしています:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        ControllerContext.HttpContext.Response.Cookies.Add(
             new HttpCookie("test", "hello") { Path = @"/admin", 
             Expires = DateTime.Now.AddDays(1)});

        return RedirectToAction("About", "Admin");
    }
}

public class AdminController : Controller
{
    public ActionResult About()
    {
        var cookieCount = HttpContext.Request.Cookies.Count;
        return View();
    }
}

Index アクションが Admin/About アクションにリダイレクトされると、Cookie は取得されず、cookieCount はゼロになります。

cokie のパスを「/」に変更すると、cookieCount が 1 に設定されていても問題なく動作します。

私は何を間違っていますか?

4

1 に答える 1

0

大文字と小文字が区別されます。試してみてください:Path = @"/Admin"にリダイレクトする場合/Admin/About。または、小文字の URL を使用してください。

于 2012-05-13T08:32:36.967 に答える