如何设置整个站点中用于表示ASP.NET用户的用户变量(或cookie,不使用会话) [英] how to Set a user variable (or cookie, don't use session) which is used throughout the site to represent user in ASP.NET
本文介绍了如何设置整个站点中用于表示ASP.NET用户的用户变量(或cookie,不使用会话)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
设置一个用户变量(或cookie,不使用会话),在整个站点中用来表示ASP.NET中的用户
Set a user variable (or cookie, don't use session) which is used throughout the site to represent user in ASP.NET
推荐答案
Hello Sailaja,
你可以像这样编码,
Hello Sailaja,
you can code like this,
//add a username Cookie
Response.Cookies["userName"].Value = "Username";
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(10);
//Can Limit a cookie to a certain Domain
Response.Cookies["domain"].Domain = "Codeproject.com";
//request a username cookie
if(Request.Cookies["userName"] != null)
lblUserName.Text = Server.HtmlEncode(Request.Cookies["userName"].Value);
注意:不应将任何敏感信息存储在cookie中。< br $>
所有最佳:)
Note:No sensitive information should be stored in a cookie.
All the Best:)
这篇关于如何设置整个站点中用于表示ASP.NET用户的用户变量(或cookie,不使用会话)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文