从编码链接ASP.NET获取参数? [英] Getting Parameter From Encoded Link ASP.NET ?
问题描述
我必须从编码链接中获取参数.
链接的第一种格式如下: About.aspx?parameter = bla
但是由于需要,链接像
一样发送给用户
About.aspx?parameter%3Dbla
从链接 About.aspx?parameter%3Dbla ,我应该获取参数(bla).
当我尝试使用
正常获取参数时
Request.QueryString ["parameter"]或HttpContext.Current.Request ["parameter"],它们返回null.
感谢您的提前答复..
I have to get a parameter from an encoded link .
The first format of link is like : About.aspx?parameter=bla
But because of a requirement the link is sended to the user like
About.aspx?parameter%3Dbla
From the link About.aspx?parameter%3Dbla , I should get the parameter(bla).
When I try to get parameter normally with
Request.QueryString["parameter"] or HttpContext.Current.Request["parameter"] , they returns null.
Thanks for the replies in advance..
推荐答案
发生的事情是,查询字符串中的"="已被htmlencoded为%3D.您需要先修复使用querystring创建此url的所有内容,以使其正确显示为About.aspx?parameter=bla
What has happened is that the "=" in your querystring has gotten htmlencoded into %3D. You need to fix whatever is creating this url with querystring first so that it appears properly like About.aspx?parameter=bla
它不是适当的解决方案,但可能会对您有所帮助,
只需将编码后的值保留在temp中,然后再次对其进行解码,并根据需要使用该查询字符串值即可:
Hi,its not a proper solution but it might help you,
just hold the encoded value in temp and then again decode it and use that query string value as you want to use:
public partial class About : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var myString = "parameter=\"bla\"";
var base64EncodedString = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(myString));
Response.Redirect("Default.aspx?temp=" + base64EncodedString);
}
}
现在为Default.aspx.cs页面编码:
---------------------------------------
now code for Default.aspx.cs page:
---------------------------------------
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var originalString = ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(Request.QueryString["temps"]));
lblShowName.Text = Request.QueryString["parameter"];
}
}
这篇关于从编码链接ASP.NET获取参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!