且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用session和querystring将值从一个页面传递到另一个页面

更新时间:2023-01-08 11:36:36

如何:在视图状态中保存值 [ ^ ]



如何:从视图状态读取值 [ ^ ]


为什么不想使用Session?这是您的问题的***解决方案,我假设是从用户隐藏代码并阻止他们更改它。会话的唯一其他替代方法仍然允许用户查看或更改代码。会话中的数据保留在服务器上,用户永远不会看到它。下一个***解决方案是cookie,但您可能需要加密cookie中的数据。使用会话时很麻烦。
Why don't you want to use the Session? It's the best solution for your problem, which I assume is to "hide" the code from the user and stop them changing it. The only other alternatives to the Session still allow the user to see or change the code. Data in the Session stays on the server and the user never sees it. The next best solution would be cookies, but you would probably have to encrypt the data in the cookie. It's a lot of hassle when using the session is simple.


当您将信息从一个页面传递到另一个页面时,您正在执行所谓的维护状态。为了使您的应用程序能够维护该状态,您必须将数据保存在某个地方,无论是在Session中还是在某个地方的后备数据库中。



网站本地无状态且无连接。这是一个查询/响应系统。客户端(浏览器)说嘿,给我这个页面,你的服务器(网络应用程序)会响应该页面或错误页面(如果它不存在)。两台机器之间没有进一步的连接。



因此,您的客户端代码必须传回服务器创建下一页或服务器所需的任何值必须在后台商店中维护这些信息,比如会话或数据库。



...在这里你试图不使用任何框架那样做是否可以帮助你做到这一点!
When you pass information from one page to another you are doing what's called "maintaining state". In order for your application to maintain that state you have to save the data somewhere, either in Session or in a backing database somewhere.

Web sites are natively stateless and connectionless. It's a query/response system. The client (browser) says "hey, give me this page" and your server (web app) responds with that page or an error page if it doesn't exist. There is no further connection between the two machines.

So either your client-side code has to pass back any values the server needs to create the next page or your server has to maintain that information in a backing store, like Session or a database.

...and here you are trying to do it without using any of the framework that is there to help you do that very thing!