如何在使用查询字符串时维护页面URL [英] How to maintain the page url when using query string

查看:92
本文介绍了如何在使用查询字符串时维护页面URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我创建了一个包含图书类别的Default.aspx页面。它包含一个编辑链接。在单击编辑按钮时,它将用户重定向到edit.aspx,但我通过querystring发送id,如edit.aspx?id = 5。

假设,如果用户更改了像edit.aspx?id = abc的id,它会给出异常。

Plz帮助我如何处理查询字符串。

Hello,
I made a page Default.aspx which contains category of books.It contains a edit link. On clicking edit button, it redirects the user to edit.aspx , But i send the id through querystring like edit.aspx?id=5.
Suppose, if user change the id like edit.aspx?id=abc , it gives exception.
Plz help me how to handle the query string.

推荐答案

你可以做一件事,你可以编码网址,或者你可以使用异常处理
u can do one thing u can encode the url or u can use exception handling


嗨试试这样。







Hi Try like this.



protected void Page_Load(object sender, EventArgs e)
       {
           if (!IsPostBack)
           {
               string value = Request.QueryString["id"];
               int id = 0;
               if (int.TryParse(value, out id))
               {
                   // value is valid
               }
               else
               {
                   Response.Write("Please dont modify the URL :) ");
               }
           }


       }





您也可以尝试通过编码/解码网址..



参考:http://msdn.microsoft.com/en-us/library/zttxte6w(v=vs.110).aspx [ ^ ]


这篇关于如何在使用查询字符串时维护页面URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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