ASP.net cookie没有传递数据。 [英] ASP.net cookies not passing data.

查看:112
本文介绍了ASP.net cookie没有传递数据。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cookie来管理ASP.NET应用程序中的会话状态。状态只需在浏览器会话打开时保持。


我的web.config设置为:

< system.web>

< sessionState cookieless =" UseCookies" />


我尝试使用以下代码创建Cookie:


Response.Cookies(" FLI")。值= cmpFLI


我试过:


Dim UID As New HttpCookie( UID)

UID.Value = txtUserName.Text

Response.Cookies.Add(UID)


我是使用以下代码读取cookie:


If(Request.Cookies(" UID")IsNot Nothing)然后

strUser1 = Request.Cookies( UID)。价值

结束如果


它要么不传递数据要么不读取数据。我在这里缺少什么?

解决方案

这一位:

< sessionState cookieless =" UseCookies" />


用于Session对象,而不是用于实际的.Cookies集合。

从您的描述中,您应该使用Session对象而不是Cookies


除此之外,如果您想要使用cookie,我可以毫无困难地使用这样的函数:

展开 | 选择 | Wrap | 行号

我尝试了会话对象,但我没有o在整个站点维护变量。由于我无法预测用户将采用的路径,因此很难在整个站点中考虑会话项目。


此功能代码在vb中的外观如何?



我尝试了会话对象,但我必须在整个站点中维护一个变量。由于我无法预测用户将采用的路径,因此很难在整个站点中考虑会话项目。


此功能代码在vb中的外观如何?



Session对象通过对站点的使用来维护特定最终用户的对象集合。克隆浏览器或闲置20分钟(默认时间)将清空存储在给定用户的会话对象中的数据。

会话对象可用于所有aspx页面。


如果你想为所有用户保留对象,请使用静态类(vb中的模块?)



至于我的cookie代码,它与你的几乎相同


I am trying to use cookies to manage session states in an ASP.NET application. The states need to persist only while the browser session is open.

My web.config setting is:
<system.web>
<sessionState cookieless="UseCookies"/>

I have tried using the following code to create the cookies:

Response.Cookies("FLI").Value = cmpFLI

and I have tried:

Dim UID As New HttpCookie("UID")
UID.Value = txtUserName.Text
Response.Cookies.Add(UID)

I am using the following code to read the cookies:

If (Request.Cookies("UID") IsNot Nothing) Then
strUser1 = Request.Cookies("UID").Value
End If

It is either not passing the data or not reading it. What am I missing here?

解决方案

This bit:
<sessionState cookieless="UseCookies"/>

Is used for the Session object, not for the actual .Cookies collection.
From your description, you should be using the Session object anyway and not the Cookies

That aside, if you reall want cookies, I''ve had no trouble using a function like this:

Expand|Select|Wrap|Line Numbers


I tried the session object but I have to maintain a variable throughout the site. Since I can''t predict the path that the user will take, it is difficult to account for the session item throughout the site.

How does this function code look in vb?


I tried the session object but I have to maintain a variable throughout the site. Since I can''t predict the path that the user will take, it is difficult to account for the session item throughout the site.

How does this function code look in vb?

The Session object maintains a collection of objects for a particular end user through out their use of the site. Clossing the browser, or going idle for 20mins(default time) will empty the data stored in the session object for the given user.
The session object is available to all aspx pages.

If you want to hold objects for all users use a static class (module in vb?)



As for my cookie code, it was pretty much the same as yours


这篇关于ASP.net cookie没有传递数据。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆