I've done a whole series of "Back to Basics" posts that I encourage you to check out. Sometimes I'll do a post as a result of a reader emailing me for help and this is one such post.
我已经完成了一系列“返璞归真”的文章,我鼓励您检查一下。 有时,由于读者向我发送电子邮件以寻求帮助,因此我会发布一个帖子,而这就是这样的帖子。
A person emailed me with an ASP.NET app was behaving differently on his computer vs. another developer's computer.
一个人通过ASP.NET应用程序向我发送电子邮件,其计算机与另一位开发人员的计算机的行为有所不同。
On his machine when he hit a protected page foo.aspx?returnurl=http://mymachine.domain.com
当他访问受保护的页面时,在他的计算机上foo.aspx?returnurl = http://mymachine.domain.com
he would get a FORM element like this:
他会得到这样的FORM元素:
<form action="foo.aspx?returnurl=http://mymachine.domain.com">
but on everyone else's machines their HTML was:
但是在其他所有人的机器上,它们HTML是:
<form action="foo.aspx">
They debugging and were frustrated and eventually reached out. They said:
他们进行调试,感到沮丧,最终伸出援手。 他们说:
1. there's nothing going on in the aspx of login.aspx that would append the querystring.
1.在login.aspx的aspx中没有任何事情会追加查询字符串。
2. there's nothing going on in the code-behind of the aspx that manipulates Form.Action or messes with the Page.Render in any way.
2.在aspx的代码背后没有任何操作Form.Action或以任何方式与Page.Render混淆的事情。
So, I'm stumped, because the querystring is included on my machine, but not on others. I've tried comparing IIS components, web.config differences, application pool runtime type, machine.config differences, possible differences in Modules for IIS (IISrewrite), but nothing is giving me love.
因此,我很困惑,因为查询字符串包含在我的计算机上,但不包含在其他计算机上。 我尝试过比较IIS组件,web.config差异,应用程序池运行时类型,machine.config差异,IIS模块(IISrewrite)中可能的差异,但是没有什么能给我带来帮助。
I suggested that they assert assumptions and start diffing everything. You can see in the last paragraph that they're comparing stuff but I think you really have to diff everything.
我建议他们断定假设并开始区别对待。 您可以在上一段中看到他们正在比较东西,但我认为您确实必须区别所有东西。
When something "works here but not there" my answer is always, what has changed? What's different? If the answer is "nothing is different" I'm just gonna say it again:
当某事“在这里但不在那儿工作”时,我的答案总是不变的,那是什么改变了? 有什么不同? 如果答案是“没有什么不同”,我再说一遍:
“有什么不同?” ("What's different?")
What are some things we can check?
我们可以检查哪些内容?
- Code 码
- Do you know what's on disk?你知道磁盘上有什么吗?
- Do you know what ended up in memory? These are different things. 您知道内存中的内容吗? 这些是不同的东西。
- Configuration 组态
- There's local and machine-wide config to check有本地和机器范围的配置要检查
- Network Traffic网络流量
This is often overlooked. The Internet is not a black box, but you'd be surprised how few people hook up a packet sniffer or even just Fiddler to look at HTTP traffic.
这经常被忽略。 互联网不是一个黑匣子,但是您会惊讶地发现,很少有人挂起数据包嗅探器,甚至只是Fiddler来查看HTTP流量。
- I've talked to developers who have said "well, that's under SSL so I can't see it." Oh, my friend, if you only knew. 我已经与开发人员交谈过,他们说:“嗯,这是在SSL下进行的,所以我看不到它。” 哦,我的朋友,如果您只知道的话。
I had them do a sniff and see if there was a difference in HTTP traffic. My assumption was that the HTTP_REFERER HTTP header was different and there was some code that was causing the page to render differently.
我让他们嗅探一下,看看HTTP通信量是否有所不同。 我的假设是HTTP_REFERER HTTP标头不同,并且有一些代码导致页面呈现方式不同。
We went back and forth over a few days and my reader became frustrated and just added this line in their app's Page_Load:
我们来回走了几天,我的读者很沮丧,只是在他们的应用程序的Page_Load中添加了这一行:
this.Form.Action = Request.Url.ToString();
Here they are basically reasserting the Form action by pulling it from the URL. It's gross and it's a hack. It's a Band-Aid on Cancer.
在这里,他们基本上是通过从URL中拉动Form动作来重新声明它的。 太过分了,这是骇客。 这是癌症的创可贴。
They then started looking at the source for ASP.NET proper and then decided to disassemble the code that was running on the other person's machine. They then started to assert their assumptions.
然后,他们开始寻找ASP.NET的适当来源,然后决定反汇编在其他人的计算机上运行的代码。 然后,他们开始主张自己的假设。
Is the code running what's on disk? For a compiled language, do the binaries reflect the source?
代码是否正在运行磁盘上的内容? 对于编译语言,二进制文件是否反映了源代码?
They looked in Temporary ASP.NET files at the compiled ASPX markup pages and found this.
他们在已编译的ASPX标记页中查看了临时ASP.NET文件,并发现了这一点。
//ExternalSource("D:\WebApplications\Foo\login.aspx",27)
__ctrl.Method = "post";
//ExternalSource("D:\WebApplications\Foo\login.aspx",27)
__ctrl.Action = "login.aspx";
What? Why is someone setting the FORM Action manually? And there's a line number.
什么? 为什么有人手动设置FORM动作? 还有一个行号。
They had diff compared all the source code but not the markup/views/html.
他们已经比较了所有源代码,但没有比较markup / views / html。
Their markup:
他们的标记:
<form id="Form1" method="post" runat="server">
Other person's markup:
他人的标记:
<form id="Form1" method="post" runat="server" action="Login.aspx">
The other person had hard-coded the action in their source markup. They'd been diffing everything but the markup.
另一个人已在其源代码标记中对操作进行了硬编码。 除了标记之外,他们一直在散布一切。
When you are comparing two code-bases, make sure to compare everything or you might just lose a day or two like this person.
当您比较两个代码库时,请确保比较所有内容,否则您可能会像这个人一样失去一两天。
Thanks to my reader for sharing this and letting me in on this debugging adventure.
感谢读者的分享和让我参与这次调试冒险。
相关链接: (Related Links:)
Back To Basics: You aren't smarter than the compiler. (plus fun with Microbenchmarks)
返璞归真:动态图像生成,ASP.NET控制器,路由,IHttpHandlers和runAllManagedModulesForAllRequests
Back to Basics: Daylight Savings Time bugs strike again with SetLastModified
Good Exception Management Rules of Thumb - Back to Basics Edition
翻译自: https://www.hanselman.com/blog/back-to-basics-assert-your-assumptions-and-diff-your-source-code