我怎样才能阻止asp.net编码和放大器;在获取PARAMS? [英] How can I stop asp.net encoding & in Get params?
问题描述
我用下面的code一系列调用添加到asp.net页面的身体参数:
I am using the following code to add a series of calls to the body parameter of a page in asp.net:
uxBodyTag.Attributes["onbeforeunload"] +=
"ajaxRequest('UnlockQuery.ashx?QueryID=" + queryId.ToString() +
"&UserID=" + Session["UserID"].ToString() + "');";
这是正在呈现为:
<body id="uxBodyTag" onbeforeunload=
"ajaxRequest('UnlockQuery.ashx?QueryID=176&UserID=11648');">
&的放大器;放大器;意味着我的ASHX页面不会检索正确的变量 - 我如何从这样停止asp.net
The & means my ashx page is not retrieving the correct variables - how can I stop asp.net from doing this?
编辑:
使用
Server.UrlEn code
给我的以下内容:
Using Server.UrlEncode gives me the following:
<body id="uxBodyTag" onbeforeunload=
"ajaxRequest('UnlockQuery.ashx%3fQueryID%3d179%26UserID%3d11648')%3b">
这是差远了。
推荐答案
在HTML的符号必须连接codeD,总是无处不在,也是在属性值(&LT的内容;脚本&GT;
标签是明显的例外,很明显)。 ASP.NET做正确的事。
In HTML the ampersand needs to be encoded, always, everywhere, also in attribute values (the contents of the <script>
tag is the notable exception, obviously). ASP.NET does the right thing.
属性值将unen codeD浏览器之前,它实际上使用他们。所以,你的 onbeforeunload
属性有一个文本值:
Attribute values will be unencoded by the browser before it actually uses them. So your onbeforeunload
attribute has a literal value of:
ajaxRequest('UnlockQuery.ashx?QueryID=176&UserID=11648');
而HTML重新presentation需要有&放大器;放大器;
代替&放大器;
。浏览器通常理解的不适恩codeD版本,但一个SGML解析器会抱怨名为未知/无效的实体&放大器;用户名
while the HTML representation needs to have the &
in place of the &
. The browser usually understands the ill-encoded version as well, but an SGML parser would complain about an unknown/invalid entity named &UserID
.
这篇关于我怎样才能阻止asp.net编码和放大器;在获取PARAMS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!