以编程方式启用/禁用每个请求的 51 度重定向
简而言之,我试图弄清楚如何基于会话值、基于每个请求(不是针对每个人静态地)以编程方式启用和禁用移动电话的重定向。
背景故事如下:
我目前在 ASP.NET 应用程序中使用 51Degrees 将请求重定向到网站的移动版本。我想添加一项功能,用户可以从“设置”页面启用和禁用此重定向。每个用户的设置都不同,到目前为止,我发现禁用 51Degrees 的每个设置都是静态的。这使得为部分用户禁用它变得困难。
我的一个半解决方案是设置 firstRequestOnly="true"
并在不应该发生的情况下反转重定向。虽然 firstRequestOnly="true"
引起了许多其他令人头痛的问题(无关),所以我想将其保留在 firstRequestOnly="false"
并简单地启用/禁用重定向基于每个请求或每个用户的会话值。问题是我无法找到一种干净的方法来做到这一点。
In a nutshell, I'm trying to figure out how to programmatically enable and disable the redirection for mobile phones, based on a session value, on a per request basis (not statically for everyone).
Here's the back story:
I'm currently using 51Degrees in my ASP.NET application to redirect requests to the mobile version of the site. I would like to add a feature where users can enable and disable this redirection from a "Settings" page. The setting will be different for each user, and so far every setting I've found to disable 51Degrees is static. This makes it difficult to disable it for a subset of users.
One semi-solution I had was to set firstRequestOnly="true"
and reverse the redirect if it wasn't supposed to happen. Although firstRequestOnly="true"
has caused a number of other headaches (unrelated) so I would like to keep it at firstRequestOnly="false"
and simply enable/disable the redirection based on a session value per request, or per user. The problem is that I can't figure out a clean way to do this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据您的用户在其个人资料中选择的设置,在页面预渲染事件中设置 cookie。您需要将firstRequestOnly 设置为true。如果用户不希望重定向,则应设置很长的到期时间,如果用户不想重定向,则应设置较短的到期时间。
Set the cookie in the page prerender event based on the setting your user has choosen in their profile. You would need to have firstRequestOnly set to true. If the user does not want redirection it should have a very long expiry time, if they do then set a short expiry time.
我最终只是下载了源代码,并添加了一个选项,以便在某个会话字段存在并设置为 true 时选择退出重定向。这允许我根据用户在设置部分中的设置从代码中设置会话值。这不是最好的解决方案,因为以后升级 51Degrees 会更加困难,但它确实有效。
I ended up just downloading the source code and adding in an option to opt-out of the redirect if a certain session field was present and set to true. This allowed me to set that session value from my code depending on what the user had setup in the settings section. Not the best solution since it's going to be more difficult to upgrade 51Degrees down the road, but it works.