ASHX 呈现为损坏的图像

发布于 2024-10-31 17:25:06 字数 758 浏览 1 评论 0原文

我在渲染验证码图像的 ASHX 处理程序方面遇到了一个非常棘手的问题。真正让人烦恼的是,两个月前它工作得很好,当我今天再次回到它时,它已经停止工作了。

我得到的是一个经常抛出验证码的页面。这是来自质询示例的标记:

<img class="challengedtl" src="Challenge.ashx?tkn=0057ea27-4d35-4850-9c6f-7a6fdc9818e2"/>

GUID 引用 SQL 表中的一条记录,其中包含验证码的实际内容以及验证码质询的状态,即是否已处理,如果已处理,用户是否得到处理是的,等等。

在找到此标记的页面上,图像显示为损坏的 jpeg。当我在 ASHX ProcessRequest() 方法中放置断点时,我可以看到 ASHX 从未被调用。

当我从源属性中取出 URL 并直接从浏览器的地址栏中运行它时,我在 ProcessRequest 中遇到了断点,并且捕获图像呈现得很好。

我不认为我的 ASHX 代码有问题,因为当我直接调用它时它可以工作。问题似乎在于为什么主页没有调用 ASHX。鉴于这在二月份是有效的,我无法解释发生了什么。

我知道从那时起我的机器发生了一些问题。我怀疑 Windows 更新或服务包有什么用。原因是我的验证码处理包括跟踪呼叫者的 IP 地址。当此功能正常运行时,我的本地主机被注册为 127.0.0.1 (IPv4),但现在它被注册为 ::1 (IPv6)。可能是一条红鲱鱼。

有谁知道可能导致此问题的原因,或者您对如何解决此问题有任何建议吗?

I've got a really vexxing problem with an ASHX handler that renders a captcha image. The thing that makes it really vexxing is that it was working fine two months ago and when I went back to it again today it had stopped working.

What I've got is a page that throws in a captcha every so often. This is the markup from an example of a challenge:

<img class="challengedtl" src="Challenge.ashx?tkn=0057ea27-4d35-4850-9c6f-7a6fdc9818e2"/>

The GUID references a record in a SQL table that contains the actual content of the captcha as well as the status of the captcha challenge, i.e. has it been processed and if so did the user get it right etc.

On the page where this markup is found, the image displays as a broken jpeg. When I drop a breakpoint in the ASHX ProcessRequest() method I can see that the ASHX is never being called.

When I take the URL out of the source attribute and run it directly from the address bar in my browser, then I hit my break point in ProcessRequest and the captch image is rendered just fine.

I don't believe that my ASHX code is the problem, since it works when I call it directly. The problem seems to be with why the ASHX isn't being called by the main page. Given that this was working in February I am at a loss to explain what is going on.

I know that something has happened to my machine since then. I suspect a Windows Update or a service pack for something. The reason for this is that my captcha processing includes tracking the IP address of the caller. Back when this was working my local host was being registered as 127.0.0.1 (IPv4) but now it is being registered as ::1 (IPv6). Probably a red herring.

Does anyone know what might be causing this or do you have any suggestions for how to troubleshoot this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱你是孤单的心事 2024-11-07 17:25:06

该处理程序是否与包含您上面发布的 html 的页面位于同一文件夹中?

Is the handler in the same folder as the page containing the html you posted above?

妞丶爷亲个 2024-11-07 17:25:06

以下是两个关键部分:

当我在 ASHX ProcessRequest() 方法中放置断点时,我可以看到 ASHX 从未被调用。

src="Challenge.ashx?tkn=0057ea27-4d35-4850-9c6f-7a6fdc9818e2"

把它们放在一起,我们可以推测你的 src 属性中的路径是错误的。

这只是一个图像标签。如果 html 加载,它将发送对该资源的请求。由于您的断点没有被命中,这只能意味着您没有在允许断点的地方进行测试,或者它将请求发送到了错误的地方。

它可能就像将请求发送到站点的生产版本一样简单,使用错误的架构(即:https 与 http),或者在某处缺少文件夹或端口号。浏览器应该能够为您提供资源的完整路径——确保它符合您的期望。

Here are the two key parts:

When I drop a breakpoint in the ASHX ProcessRequest() method I can see that the ASHX is never being called.

and

src="Challenge.ashx?tkn=0057ea27-4d35-4850-9c6f-7a6fdc9818e2"

Put those together, and what we can surmise that the path in your src attribute is wrong.

It's just an image tag. If the html loads it will send a request for that resource. Since your breakpoint is not hit, it can only mean that either you aren't testing somewhere that allows breakpoints or that it's sending the request to the wrong place.

It could be as simple as sending the request to the production version of the site, using the wrong schema (ie: https vs http), or missing a folder or port number somewhere. The browser should be able to give you the entire path of the resource -- make sure this matches what you expect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文