如何隐藏 url 中的查询字符串参数

发布于 2024-11-07 14:25:00 字数 379 浏览 1 评论 0原文

我有一个面板栏,里面有一些项目。当我右键单击项目并选择“在新选项卡中打开”时,我需要在新选项卡中打开链接。 例如。如果我的页面是“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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

¢蛋碎的人ぎ生 2024-11-14 14:25:00

您可以使用 LinkBut​​ton 对象。他们将回发,然后您可以将请求重定向到所需的页面。

ASPX:

<asp:linkbutton id="lnkabcd" runat="server" text="abcd" onclick="lnkabcd_clicked"/>

C#:

public void linkabcd_clicked(object sender, EventArgs e)
{
    Response.Redirect("URL OF TARGET PAGE");
}

当然如果链接很多的话会很麻烦。您可以使用网格(希望您在问题中编写时使用它)并使用命令名称和命令参数属性捕获行事件。

要隐藏浏览器地址栏中的url,需要进行URL重写。有关 URL 重写的更多信息,请访问 codeprojectmsdn

You can use LinkButton objects. They will postback and then you can redirect requests to desired pages.

ASPX:

<asp:linkbutton id="lnkabcd" runat="server" text="abcd" onclick="lnkabcd_clicked"/>

C#:

public void linkabcd_clicked(object sender, EventArgs e)
{
    Response.Redirect("URL OF TARGET PAGE");
}

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.

有木有妳兜一样 2024-11-14 14:25:00

您可以设置一个 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.

残花月 2024-11-14 14:25:00

正如@TheVillageIdiot 所说,url 重写是一种更好的方法。但您也可以使用跨页面发布功能。看看:

标记

<asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Second.aspx" Text='<%# Bind("Text") %>' OnClientClick='<%# "LinkButton1_Click(\"" + Eval("Value") + "\")" %>' />
    </ItemTemplate>
</asp:Repeater>

<script type="text/javascript">
    function LinkButton1_Click(v) {
        document.getElementById('HiddenField1').value = v;
    }
</script>

正如您在前面的代码片段中看到的,您必须通过简单的 JavaScript 添加一个隐藏字段来存储所选项目。我还定义了一个名为 SelectedValue 的属性来获取另一侧隐藏字段的值。

代码隐藏

protected void Page_Load(object sender, EventArgs e)
{
    Repeater1.DataSource = new[] {
        new { Text = "Item 1", Value = "Item 1" },
        new { Text = "Item 2", Value = "Item 2" },
        new { Text = "Item 3", Value = "Item 3" }
    };
    Repeater1.DataBind();
}

public string SelectedValue
{
    get { return HiddenField1.Value; }
}

第二页

将以下指令添加到目标页面。

<%@ PreviousPageType VirtualPath="~/Default.aspx" %>

最后,您可以通过 Page 类的 PreviousPage 属性访问上一页。

string value = ((_Default)this.PreviousPage).SelectedValue;

As @TheVillageIdiot said, url rewriting is a better approach. But you can use cross-page posting ability as well. Check it out:

Markup

<asp:HiddenField ID="HiddenField1" runat="server" ClientIDMode="Static" />

<asp:Repeater ID="Repeater1" runat="server">
    <ItemTemplate>
        <asp:LinkButton ID="LinkButton1" runat="server" PostBackUrl="~/Second.aspx" Text='<%# Bind("Text") %>' OnClientClick='<%# "LinkButton1_Click(\"" + Eval("Value") + "\")" %>' />
    </ItemTemplate>
</asp:Repeater>

<script type="text/javascript">
    function LinkButton1_Click(v) {
        document.getElementById('HiddenField1').value = v;
    }
</script>

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

protected void Page_Load(object sender, EventArgs e)
{
    Repeater1.DataSource = new[] {
        new { Text = "Item 1", Value = "Item 1" },
        new { Text = "Item 2", Value = "Item 2" },
        new { Text = "Item 3", Value = "Item 3" }
    };
    Repeater1.DataBind();
}

public string SelectedValue
{
    get { return HiddenField1.Value; }
}

Second Page

Add following directive to the destination page.

<%@ PreviousPageType VirtualPath="~/Default.aspx" %>

Finally, you have access to the previous page via PreviousPage property of Page class.

string value = ((_Default)this.PreviousPage).SelectedValue;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文