写入Cookie并将Cookie值设置为文本框选择Vlaue

时间:2015-08-23 19:21:56

标签: asp.net cookies

我正在尝试将选定的下拉列表值存储在与此代码完美匹配的Cookie中。

[Authorize]
public ActionResult MySecretAction()
{
    // all authorized users could use this method don't matter how has been authenticated
    // we have access current user principal by calling also
    // HttpContext.User
}

[Authorize(Roles="TempUser")]
public ActionResult MySecretAction()
{
    // just temp users have accesses to this method
}

然后我想使用cookie值在page_load之后设置下拉列表的选择值。它有效,但在第一个值存储在cookie中后,我无法更改下拉值。

protected void state_DropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {
        HttpCookie StudentCookies = new HttpCookie("userloaction_cookies");
        StudentCookies.Value = state_DropDownList.SelectedValue;
        StudentCookies.Expires = DateTime.Now.AddDays(1000);
        Response.Cookies.Add(StudentCookies);
    }

我认为问题在于Page_load方法在state_DropDownList_SelectedIndexChanged方法之前触发。

有没有可行的方法让这项工作?

0 个答案:

没有答案