如何获取/跟踪asp.net传出的响应文本 [英] how to get/trace asp.net outgoing response text
问题描述
我的服务器似乎有时返回错误的HTML Web客户
my server seems to be sometimes returning wrong html to webclients
使用asp.net 4在IIS上与前preSS VS 2012的调试IM。
im using asp.net 4 with VS 2012. debugging on IIS Express.
为了调试这个问题,我还想跟踪的ASP.NET是发送HTML
in order to debug this issue, id like to trace the html that asp.net is sending
在 Global_asax_ preRequestHandlerExecute
我可以访问响应code和地位,但不能似乎发现身体HTML
in the Global_asax_PreRequestHandlerExecute
i can access the response code and status, but cant seem to find the body html
我想读的OutputStream
是这样的:
Dim ms = New MemoryStream
CurContext.Response.OutputStream.CopyTo(ms)
Dim sr = New StreamReader(ms)
Dim rtext = sr.ReadToEnd
但抛出一个引发NotSupportedException
流不支持读取。
什么想法?
非常感谢
修改
我现在测试这是肯定的。
i now tested this for sure
我在页面上的标签具有以下属性。
i have a label on the page with the following attributes
<asp:label id="l" runat="server" Font-Bold="true" Font-Size="X-Large" BackColor="Pink"/>
在浏览器中显示
当它显示就好了,如下:
when displayed in the browser it shows just fine, as follows:
<span id="C1_FormView1_l" style="background-color:Pink;font-size:X-Large;font-weight:bold;">Processed</span>
但与Web客户端下载,我得到
but when downloaded with webclient i get
<span id="C1_FormView1_l"><b><font size="6">Processed</font></b></span>
为什么是背景色失去了什么?和顺便说一句,为什么没有用更现代的风格
属性,而不是加入 B
和字体
如果我能读ResponseStream我至少知道它在哪里丢失,甚至,我不知道现在。
if i could read the ResponseStream i would at least know WHERE it gets lost, even that i dont know now.
非常感谢你。
P.S。如果.NET 4.5是这更好的话,我可能会考虑更改目标框架
P.S. if .net 4.5 is better for this, then i might consider changing the target framework
推荐答案
这并没有回答我原来的问题在技术上,但它确实解决了我是有问题的。
this does not answer my original question technically, but it does solve the issue i was having
问题是,HTML渲染wasnt正确
the problem was that the html wasnt rendering correctly
我现在记得的aspx具有自适应渲染,所以我fgured请求中使用用户代理可能是罪魁祸首。
i now remembered that aspx has adaptive rendering, so i fgured the useragent used in the request might be to blame
我改变了我的code为:
i changed my code to:
Dim myReq As HttpWebRequest = WebRequest.Create(MailUrl)
myReq.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1"
Dim resp As HttpWebResponse = myReq.GetResponse
Dim stream = resp.GetResponseStream
Dim rdr = New StreamReader(stream)
Dim BodyText = rdr.ReadToEnd
和现在的HTML是正确的现代HTML5 / CSS3标记渲染
and now the html is rendering in correct modern Html5/Css3 markup
我AP preciate您的帮助和指导。
i appreciate your help and guidance.
这篇关于如何获取/跟踪asp.net传出的响应文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!