English 中文(简体)
最好是在伙伴关系中使用海滩。 NET项目
原标题:What is the best approach of using cache in ASP.NET project?

我正在协会的一个项目中工作。 NET。

用户名在用户记录中首次出现。 例如: 如果目前的用户第一次登入和访问某个网页,就会有一个人满为患的窗口,否则不会发生。

用户名应当储存在客户浏览器上,在用户关闭浏览器之前仍然有效。

My question is, what is the best approach of doing this?

Any limitations if I am using ASP.Net Cache to store the username? For example:

Cache["myCache"] = username;

and remove the item from the cache when page loads for the first time.

if (!Page.IsPostBack)
{
     Cache.Remove("myCache");
}

这一点可以提出意见。 事先感谢你。

最佳回答

使用<代码>HttpCookie,并视需要确定到期:

If you do not set the cookie s expiration, the cookie is created but it is not stored on the user s hard disk. Instead, the cookie is maintained as part of the user s session information. When the user closes the browser, the cookie is discarded.

ASP.NET Cookies Overview

//write
HttpCookie myCookie = new HttpCookie("UserSettings");
myCookie["Font"] = "Arial";
myCookie["Color"] = "Blue";
//myCookie.Expires = DateTime.Now.AddDays(1d);
Response.Cookies.Add(myCookie);

//read
if (Request.Cookies["UserSettings"] != null)
{
    string userSettings;
    if (Request.Cookies["UserSettings"]["Font"] != null)
    { userSettings = Request.Cookies["UserSettings"]["Font"]; }
}

How to: Read a Cookie

问题回答

你们是否考虑使用本届会议? 所有届会都共用藏匿点,这将要求您在届会结束后删除该项目。 会议没有遇到这一问题,而是直接与每届用户会议一致,在届会结束时自动取消。 注:我假定你再谈论显示名称,而不是用户标识。 可查阅HttpContext.User.Identity.Name

As for showing the pop up, you might want to use cookies for this. Have some javascript that runs on the page that checks for the cookie, displays the popup if it s not there, and then sets the cookie (as a session cookie) so that the popup isn t show again. A cookie could also be used (not a session cookie) if you only wanted the popup to show the first time someone logs in or only periodically on login, etc.

我不想为此而ach。 相反,协会。 该网络支持成员和作用。 如果你不希望使用上述 co基办法,我就利用这一办法管理你们的成员。 关于登页,如果只用一页,则可以使用 co或用户简介。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签