如何隐藏 url 中的查询字符串参数
我有一个面板栏,里面有一些项目。当我右键单击项目并选择“在新选项卡中打开”时,我需要在新选项卡中打开链接。 例如。如果我的页面是“http:localhost/MyPage” 我的网格是:
名称
- abc
- bcd
- cde
当我单击第二个项目时,navigateUrl 将是“http:localhost/MyPage/?Name=bcd”
这工作正常。 但我想隐藏网址中的名称。有没有其他方法,我可以将名称传递到下一页,而无需在网址中公开它。我可以使用会话,但不幸的是,我无法将其编写为默认上下文菜单的代码。
I've a panel bar with some items in it. When I right click on the items and if I select "open in new tab", I need to open the link in a new tab.
For eg. if my page is "http:localhost/MyPage"
My grid is:
Name
- abc
- bcd
- cde
When I click on the second item, the navigateUrl would be "http:localhost/MyPage/?Name=bcd"
This works fine.
But I want to hide the name in the url. Is there any other way, I can pass the name to next page without exposing it in the url. I could use sessions, but unfortunately, I cannot write it as a code for the default context menu.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
LinkButton
对象。他们将回发,然后您可以将请求重定向到所需的页面。ASPX:
C#:
当然如果链接很多的话会很麻烦。您可以使用网格(希望您在问题中编写时使用它)并使用命令名称和命令参数属性捕获行事件。
要隐藏浏览器地址栏中的url,需要进行URL重写。有关 URL 重写的更多信息,请访问 codeproject 和 msdn。
You can use
LinkButton
objects. They will postback and then you can redirect requests to desired pages.ASPX:
C#:
Ofcourse it will be very cumbersome if you have lot of links. You can use grid (hope you are using it as you write in your question) and catch row event with command name and command argument properties.
To hide the url in addressbar of the browser, you need to do URL rewriting. For more on URL rewriting please visit these pages on codeproject and msdn.
您可以设置一个 cookie - 这样下次用户返回时您甚至可以将他们返回到同一页面(如果您愿意)。
您可能会发现本文很有帮助决定这是否适合您。
如果您需要在客户端设置 cookie,那么这篇文章应该可以帮助您。
You could set a cookie - that way the next time the user returns you could even return them to the same page (if you wanted to).
You may find this article helpful when deciding if this is a good option for you.
If you need to set the cookie on the client-side, then this article should help you out.
正如@TheVillageIdiot 所说,url 重写是一种更好的方法。但您也可以使用跨页面发布功能。看看:
标记
正如您在前面的代码片段中看到的,您必须通过简单的 JavaScript 添加一个隐藏字段来存储所选项目。我还定义了一个名为
SelectedValue
的属性来获取另一侧隐藏字段的值。代码隐藏
第二页
将以下指令添加到目标页面。
最后,您可以通过
Page
类的PreviousPage
属性访问上一页。As @TheVillageIdiot said, url rewriting is a better approach. But you can use cross-page posting ability as well. Check it out:
Markup
As you can see in the preceding code snippet, you have to add a hidden field to store the selected item by a simple javascript. Also I defined a property, called
SelectedValue
to get the value of the hidden field on the otherside.Code Behind
Second Page
Add following directive to the destination page.
Finally, you have access to the previous page via
PreviousPage
property ofPage
class.