我得到cookie的controller,我想传递cookie给ChekLogin对方法
login.cs是什么饼干的种类上ChekLogin
public ActionResult test()
{
Login.ChekLogin(Request.Cookies["Account"];
}
Run Code Online (Sandbox Code Playgroud)
checklogin方法
public static bool ChekLogin()// what is type of cookie
{
}
Run Code Online (Sandbox Code Playgroud)
Request.Cookies["Account"]返回一个HttpCookie,这是您的CheckLogin方法可以作为参数的类型:
public static bool ChekLogin(HttpCookie cookie)
{
if (cookie != null)
{
string cookieValue = cookie.Value;
}
}
Run Code Online (Sandbox Code Playgroud)
当然,如果请求中不存在cookie,Request.Cookies["Account"]则返回null,因此请确保在ChekLogin方法中考虑到这一点.
此外,只是为了确保您不会重新发明某些轮子或打开您的网站以应对安全风险,请确保您已阅读过Forms Authentication in ASP.NET.
| 归档时间: |
|
| 查看次数: |
223 次 |
| 最近记录: |