HttpUtility.UrlEncode 和 Application_Start
根据 http://ayende.com/blog/4599/hunt-the-bug< /a>,我遇到了其中一种情况,其中“响应在此上下文中不可用”。
大大简化了,以下内容在 Windows Server 2008/IIS7/ASP.NET 4.0 上的某些情况下引发异常
public class Global : HttpApplication
{
public void Application_Start(object sender, EventArgs e)
{
HttpUtility.UrlEncode("Error inside!");
}
}
我见过的解决方案涉及以下其中一项:
- 像 Ayende 那样“编写我自己的 HttpUtility”(好吧,采取来自 Mono 的一个并对其进行修改)以避免此错误。”
- 或确定是否使用 HttpEncoder.Default 来代替。我正在尝试找出最好的方法。
- 或按照 Server.UrlEncode 与 HttpUtility.UrlEncode
也许这不是我最好的谷歌搜索日,但是如何实现 HttpEncoder.Default?
建议?
As per http://ayende.com/blog/4599/hunt-the-bug, I've run into one of those scenarios whereby "Response is not available in this context".
Greatly simplified, the following throws an exception in certain scenarios on Windows Server 2008/IIS7/ASP.NET 4.0
public class Global : HttpApplication
{
public void Application_Start(object sender, EventArgs e)
{
HttpUtility.UrlEncode("Error inside!");
}
}
The solutions that I've seen involve one of the following:
- Do as Ayende did and "write my own HttpUtility (well, take the one from Mono and modify it) to avoid this bug."
- or determine whether using HttpEncoder.Default instead does the trick. I'm trying to track down how best to do this.
- or use Uri.EscapeDataString as per Server.UrlEncode vs. HttpUtility.UrlEncode
Maybe it's not my best googling day, but how to implement HttpEncoder.Default?
Recommendations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以尝试这个编码
如果你觉得不舒服或者你的应用程序没有在完全信任级别运行,试试这个
我知道这仍然不是最好的方法,但如果我们不使用最好的方法是什么HttpUtility.UrlEncode!..
You can try this for encoding
And if you don't feel comfortable with or your application is not running in FULL trust level, try this
I Know it is not still the best way but what could the best way be if we don't use HttpUtility.UrlEncode!..
需要完全信任
Requires FULL trust