我编写了这个实用程序类来保存和检索HttpCookies.
它似乎没有工作,即没有检索到Cookie ...
public class AspNetUtil
{
private Page _page = null;
public AspNetUtil(Page page)
{
_page = page;
}
public bool SaveInCookie(string cookieName, string valueKey, string valueToBeStored, int expiryTimeInMinutes)
{
bool success = false;
try
{
HttpCookie cookie = null;
if(_page.Request.Cookies[cookieName] == null)
{
cookie = new HttpCookie(cookieName);
}
else
{
cookie = _page.Request.Cookies[cookieName];
}
cookie.Values.Add(valueKey, valueToBeStored);
cookie.Expires = DateTime.Now.AddMinutes(expiryTimeInMinutes);
_page.Response.Cookies.Add(cookie);
}
catch(Exception ex)
{
success = false;
throw ex;
}
return success;
}
public string GetCookieValue(string cookieName, string valueKey)
{
string cookieValue = string.Empty;
try
{
cookieValue = (string)_page.Response.Cookies[cookieName].Values[valueKey];
}
catch (Exception ex)
{
cookieValue = string.Empty;
throw ex;
}
return cookieValue;
}
}
Run Code Online (Sandbox Code Playgroud)
谁能告诉我可能是什么问题?
| 归档时间: |
|
| 查看次数: |
2223 次 |
| 最近记录: |