/*自定义导航栏*/

【ASP】简单Url编码和Url解码实例

描述:在数据传输或读取时,有些敏感数据不宜显示传输,特别涉及机密或财务信息,因此使用编码技术尤为重要。

简单实例:

URL编码代码:

protected void Button1_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == null)
            {
                Response.Write("<script>alert('文本不存在,无法编码')</script>");
            }
            else
            {
                string str = TextBox1.Text;
                string UrlEncode = Server.UrlEncode(str);
                Label1.Text = "编码后的数据" + UrlEncode;
            }

        }

Url解码代码:

        protected void Button2_Click(object sender, EventArgs e)
        {
            if (TextBox1.Text == null)
            {
                Response.Write("<script>alert('文本不存在,无法编码')</script>");
            }
            else
            {
                string str = TextBox1.Text;
                string UrlDecode = Server.UrlDecode(str);
                Label2.Text = "编码后的数据" + UrlDecode;
            }
        }

扩展:加密类别的其他方式

posted @ 2012-11-14 11:20  伏草惟存  阅读(662)  评论(0编辑  收藏  举报