什么是处理固定链接时,页面取决于会议的正确方法? [英] What is the right way to handle permalinks when the page depends on the session?

查看:116
本文介绍了什么是处理固定链接时,页面取决于会议的正确方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的情况:我有,你开始以显示国家名单的屏幕的应用程序。您可以选择一个国家,该应用程序使用,直到您更改它这成为环境的国家。该国环境中存储会话,因此应用程序不必围绕CountryId通过在每一个URL。但我也想支持固定链接到国家的具体内容,所以我想,需要有一个获取固定链接按钮,创建一个一个固定链接确实包含CountryId,因为它显然有独立工作本届会议。

Here's the situation: I've got an application where you begin at a screen showing a list of countries. You choose a country, and this becomes the ambient country that the application uses until you change it. This ambient country is stored in the Session so the application doesn't have to pass around a CountryId in every single url. But I also want to support permalinks to country specific content, so I guess there needs to be a "Get Permalink" button, which creates a permalink that does contain the CountryId, because it obviously has to work independent of the current session.

这里的问题:我的理解是,因为选择一个国家改变了会话状态,应该只能通过POST做到这一点。不过,如果用户通过GET来与含永久链接,例如CountryId = 123,会发生什么?如果页面更新全国123会话?在这种情况下,它会被打破,你只能通过POST更改会话的规则。但是,如果它的的更改会话,那么所有的code,它依赖于会议将不工作,我得有code冗余的方式来产生页。

Here's the question: My understanding is that because selecting a country changes the session state, one should only do it via POST. But then if the user comes in via GET with a permalink containing, e.g. CountryId=123, what should happen? Should the page update the Session with country 123? In this case, it would be breaking the rule that you can change the session ONLY via POST. But if it doesn't change the session, then all the code that relies on the session won't work, and I'd have to have code redundant ways to generate the page.

,如果页面有某种机制来称使用会话值,但与任何查询字符串值覆盖,如果有一个(且根本不修改会话) ?

OR, should the page have some sort of mechanism for saying "use the session value, but override with any query string value if there is one (and don't modify the session at all)?

,我误解了POST规则完全?

OR, am I misunderstanding the POST rule entirely?

推荐答案

在这里真正的问题是,您使用的是会话。你不能提供永久链接,因为当用户按照该链接后,您已经存储在会话中的数据可能已过期。所以,你必须以某种方式继续存在这个数据到一个更持久的数据存储,当有人要求你生成一个固定链接。因此,当用户请求一个固定链接,你会继续前进,坚持了用来执行搜索到您的数据存储,并获得一个唯一的ID将允许您以后获取它们所有这些搜索条件。然后给用户提供了以下永久链接: /控制器/搜索/ ID ,其中ID重新presents的唯一标识符达将允许您从您的数据存储读取标准,执行搜索并重建页面,因为它是。

The real issue here is the fact that you are using a Session. You cannot provide permalinks because the data that you have stored in the session might have expired when the user follows this links later. So you must somehow persist this data into a more durable datastore when someone requests you to generate a permalink. So when a user asks for a permalink you will go ahead and persist all those search criteria that were used to perform the search into your data store and obtain an unique id that will allow you to fetch them later. Then give the user the following permalink: /controller/search/id where the id represents the unique identifier tat will allow you to fetch the criteria from your data store, perform the search and reconstruct the page as it was.

这篇关于什么是处理固定链接时,页面取决于会议的正确方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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