.NET 中的 URL 重写在无 cookie 会话中表现不佳
我目前正在使用 Intelligencia 的 URL Rewriter .NET HTTPModule 来重写 URL。 我正在使用其自定义转换功能,该功能允许我提供一个包含执行实际 URL 转换的方法的程序集。
我打开了无 cookie 会话,这对 URL 重写器造成了一些干扰。
所以,假设我的服务器上的路径是这样的:
http://www.foobar.com/actualPath/index.aspx
但我想要使用 url 重写使路径看起来像这样:
http://www.foobar.com/rewritingPath/index.aspx
我做了一个脚本输出以下内容:
- Request.Url(来自我的代码隐藏)
- Request.RawUrl(来自我的代码隐藏)
- document.location(来自 javascript)
我在地址栏中输入以下内容:
http://www.foobar.com/rewritingPath/index.aspx
当我有禁用 cookieless 会话,一切正常。 我的脚本输出以下值:
- Request.Url 显示为 http://www.foobar.com/actualPath/index.aspx
- Request.RawUrl 显示为 /rewritingPath/index.aspx
- document.location 显示为 http://www.foobar.com/rewritingPath/index.aspx
- 地址栏中的 URL 与我最初输入的内容保持不变。
但是,当我启用无 cookie 会话时,事情就会出错。 我的脚本输出以下值:
- Request.Url 显示为 http://www.foobar.com/actualPath/index.aspx
- Request.RawUrl 显示为 /actualPath/index.aspx
- document.location 显示为 http://www.foobar.com/actualPath/index.aspx
- 地址栏中的 URL 以某种方式发生改变,因此显示为:
http://www.foobar.com/(S(SESSIONID) )/actualPath/index.aspx
但这是一件奇怪的事情——页面的 OnLoad 事件只触发一次。 那么这是怎么回事呢? .NET 是否正在执行页面重定向,但在 OnLoad 事件有机会触发之前执行?
我想做的是将 rewritingPath 保留在地址栏中。 我希望 document.location 返回重写的Path。 我希望 Request.RawUrl 返回重写的Path。 这对于无 cookie 会话来说可能吗? 或者.NET 的无cookie 会话机制是否使这种行为变得不可能?
感谢您的时间和帮助。
I'm currently using Intelligencia's URL Rewriter .NET HTTPModule to rewrite URLs. I am using its Custom Transform feature, which allows me to supply an assembly containing a method that performs the actual URL transform.
I have cookieless sessions turned on, and this is causing some interference with the URL Rewriter.
So, let's say that the path on my server is this :
http://www.foobar.com/actualPath/index.aspx
But I want to use url rewriting to make the path look like this :
http://www.foobar.com/rewrittenPath/index.aspx
I made a script to output the following :
- Request.Url (from my codebehind)
- Request.RawUrl (from my codebehind)
- document.location (from javascript)
I type the following into my address bar :
http://www.foobar.com/rewrittenPath/index.aspx
When I have cookieless sessions disabled, everything works as it should. My script outputs the following values :
- Request.Url shows up as http://www.foobar.com/actualPath/index.aspx
- Request.RawUrl shows up as /rewrittenPath/index.aspx
- document.location shows up as http://www.foobar.com/rewrittenPath/index.aspx
- The URL in the address bar remains unchanged from what I originally typed in.
However, when I have cookieless sessions enabled, things go awry. My script outputs the following values :
- Request.Url shows up as http://www.foobar.com/actualPath/index.aspx
- Request.RawUrl shows up as /actualPath/index.aspx
- document.location shows up as http://www.foobar.com/actualPath/index.aspx
- The URL in the address bar somehow becomes altered, so it shows up as :
http://www.foobar.com/(S(SESSIONID))/actualPath/index.aspx
But this is the strange thing -- the OnLoad event for the page only ever fires once. So what is going on here? Is .NET doing a page redirect, but doing it before the OnLoad event has a chance to fire?
What I would like to do is keep the rewrittenPath in the address bar. I would like document.location to return the rewrittenPath. I would like Request.RawUrl to return the rewrittenPath. Is this possible with cookieless sessions? Or does .NET's cookieless session mechanism make this behavior impossible?
Thank you for your time and help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无 Cookie 会话只是将会话 ID 放入 URL 中,而不是放入会话 cookie 中。 因此,URLRewriter.NET 的 URL 映射需要考虑此行为。 你在做这个吗? 如果您希望能够在有或没有 cookie 的情况下运行,我希望您有规则来匹配 cookie 和无 cookie URL 模式。
Cookieless sessions just put the session ID in the URL instead of into a session cookie. Hence, your URL mappings for URLRewriter.NET need to take this behaviour into account. Are you doing this? If you want to be able to run with or without cookies, I would expect you to have rules to match both the cookie and cookieless URL patterns.