Is there any way to preserve data throughout web application session without using session object or database?
有没有办法在整个Web应用程序会话中保留数据而不使用会话对象或数据库?
7 个解决方案
#1
Here are some options for persisting data:
以下是一些持久化数据的选项:
- Session
- Cookies
- URL (querystring params typically)
- hidden form variables (including ViewState)
- javascript data (e.g., write an array back to client on each request)
- use IFRAMEs or framesets so that parent page doesn't change and can thus maintain state for the application
URL(通常是查询字符串参数)
隐藏的表单变量(包括ViewState)
javascript数据(例如,在每个请求上将数组写回客户端)
使用IFRAME或框架集,以便父页面不会更改,从而可以维护应用程序的状态
#2
You can pass them through the URL using
您可以使用通过URL传递它们
response.redirect("URL")
OR if you want to hide the variables
或者如果要隐藏变量
Server.Transfer("URL",True)
#3
There's also ViewState, but you need to be careful with that.
还有ViewState,但你需要小心。
#4
You've a couple of options... you could persist everything on the query string e.g.
你有几个选择...你可以在查询字符串上保留所有内容,例如
http://www.example.com/MyPage.aspx?PersistedValue1=Value1&PersistedValue2=Value2
Or you could store them in Viewstate/Cache/Application vars if they're page level or global settings.
或者,如果它们是页面级别或全局设置,您可以将它们存储在Viewstate / Cache / Application变量中。
Though I'm not really sure how any of these are any better than using Session. Why don't you want to use that.
虽然我不确定这些中的任何一个比使用Session更好。你为什么不想用它。
#5
It depends what it is about Session and Databases that you don't like. For example:
这取决于你不喜欢的会话和数据库。例如:
You could setup a seperate process (like a Windows Service) to store session state information for you. That process could keep the information in memory or in files, whatever you like really. Checkout this article for more info.
您可以设置一个单独的进程(如Windows服务)来为您存储会话状态信息。无论您真正喜欢什么,该过程都可以将信息保存在内存或文件中。查看这篇文章了解更多信息。
You could effectively implement you're own session system that stored user specific implementation in XML files on the web server.
您可以有效地实现自己的会话系统,该系统将用户特定的实现存储在Web服务器上的XML文件中。
You could pass information from page to page using QueryString parameters.
您可以使用QueryString参数将信息从一个页面传递到另一个页面。
You could use the asp.net Cache object and key the information using a UserID.
您可以使用asp.net Cache对象并使用UserID键入信息。
#6
You can create a new GUID that you send as a cookie and store the GUIDs in a custom object saved in a application object. Having said that, your application will likely perform better with the session management built into ASP.NET.
您可以创建一个作为cookie发送的新GUID,并将GUID存储在保存在应用程序对象中的自定义对象中。话虽如此,使用ASP.NET内置的会话管理,您的应用程序可能会表现更好。
#7
Not session? Then use Database it is the next best!
不是会话?然后使用数据库它是次佳的!
#1
Here are some options for persisting data:
以下是一些持久化数据的选项:
- Session
- Cookies
- URL (querystring params typically)
- hidden form variables (including ViewState)
- javascript data (e.g., write an array back to client on each request)
- use IFRAMEs or framesets so that parent page doesn't change and can thus maintain state for the application
URL(通常是查询字符串参数)
隐藏的表单变量(包括ViewState)
javascript数据(例如,在每个请求上将数组写回客户端)
使用IFRAME或框架集,以便父页面不会更改,从而可以维护应用程序的状态
#2
You can pass them through the URL using
您可以使用通过URL传递它们
response.redirect("URL")
OR if you want to hide the variables
或者如果要隐藏变量
Server.Transfer("URL",True)
#3
There's also ViewState, but you need to be careful with that.
还有ViewState,但你需要小心。
#4
You've a couple of options... you could persist everything on the query string e.g.
你有几个选择...你可以在查询字符串上保留所有内容,例如
http://www.example.com/MyPage.aspx?PersistedValue1=Value1&PersistedValue2=Value2
Or you could store them in Viewstate/Cache/Application vars if they're page level or global settings.
或者,如果它们是页面级别或全局设置,您可以将它们存储在Viewstate / Cache / Application变量中。
Though I'm not really sure how any of these are any better than using Session. Why don't you want to use that.
虽然我不确定这些中的任何一个比使用Session更好。你为什么不想用它。
#5
It depends what it is about Session and Databases that you don't like. For example:
这取决于你不喜欢的会话和数据库。例如:
You could setup a seperate process (like a Windows Service) to store session state information for you. That process could keep the information in memory or in files, whatever you like really. Checkout this article for more info.
您可以设置一个单独的进程(如Windows服务)来为您存储会话状态信息。无论您真正喜欢什么,该过程都可以将信息保存在内存或文件中。查看这篇文章了解更多信息。
You could effectively implement you're own session system that stored user specific implementation in XML files on the web server.
您可以有效地实现自己的会话系统,该系统将用户特定的实现存储在Web服务器上的XML文件中。
You could pass information from page to page using QueryString parameters.
您可以使用QueryString参数将信息从一个页面传递到另一个页面。
You could use the asp.net Cache object and key the information using a UserID.
您可以使用asp.net Cache对象并使用UserID键入信息。
#6
You can create a new GUID that you send as a cookie and store the GUIDs in a custom object saved in a application object. Having said that, your application will likely perform better with the session management built into ASP.NET.
您可以创建一个作为cookie发送的新GUID,并将GUID存储在保存在应用程序对象中的自定义对象中。话虽如此,使用ASP.NET内置的会话管理,您的应用程序可能会表现更好。
#7
Not session? Then use Database it is the next best!
不是会话?然后使用数据库它是次佳的!