将PHP“setrawcookie()”翻译成.NET

时间:2012-07-23 21:05:16

标签: php .net cookies

我需要将以下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);

?>

2 个答案:

答案 0 :(得分:0)

Response.Cookies["FontDownloaded"].Value = 1;
Response.Cookies["FontDownloaded"].Expires = DateTime.Now.AddDays(1);

答案 1 :(得分:0)

查看This page

如果要使用默认的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);