-4

我需要将以下 PHP 脚本转换为 .NET,但在 setrawcookie() 的 C#/ASP.NET 等效项上找不到任何文档:

<?php
    $type = $_REQUEST['type'];
    $location = "Location: /includes/fonts/universltstd-lightultracn-webfont.".$type;

    // create a cookie
    setrawcookie("FontDownloaded", 1, time()+3600*24, '/');
    header($location);

?>
4

2 回答 2

0
Response.Cookies["FontDownloaded"].Value = 1;
Response.Cookies["FontDownloaded"].Expires = DateTime.Now.AddDays(1);
于 2012-07-23T21:10:37.383 回答
0

看看这个页面

如果要使用默认的 ASP.NET Cookie

Response.Cookies["UserSettings"]["Font"] = "Arial";
Response.Cookies["UserSettings"]["Color"] = "Blue";
Response.Cookies["UserSettings"].Expires = DateTime.Now.AddDays(1d);

如果你想设置一个新的 cookie

HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie["Font"] = "Arial";
myCookie["Color"] = "Blue";
myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);
于 2012-07-23T21:10:46.167 回答