ImageUrl 更改后 ASP.NET 图像控件未更新
我对 ASP.NET 相当陌生,当然碰巧遇到了一些奇怪的问题。
问题很受欢迎,但我发现没有一个回复对我有用。
我有一个简单的图像:
<asp:Image ID="userImage" runat="server" ImageAlign="Right" />
在代码隐藏中:
If Not Session("selecteduser") Is Nothing Then
userImage.ImageUrl = "~/showphoto.aspx?user=" & Session("selecteduser")
End If
并且图像不会改变。它甚至不会启动 showphoto.aspx 代码。 该属性已更改(因为下次我进入它时,它已更改),但 showphoto 从未被触发。
我知道图像缓存问题,但我什至无法获取一张图像,更不用说它是否已更改。 当然有一个非常简单的解释,但我已经为此奋斗了两天但无济于事。
I'm fairly new to ASP.NET and of course happened to stumble some strange problem.
Problem is very popular, but none of the replies I found worked for me.
I have a simple image:
<asp:Image ID="userImage" runat="server" ImageAlign="Right" />
And in codebehind:
If Not Session("selecteduser") Is Nothing Then
userImage.ImageUrl = "~/showphoto.aspx?user=" & Session("selecteduser")
End If
And the image doesn't change. It doesn't even fire up the showphoto.aspx code.
The property is changed (because next time i step into it, it's changed), but showphoto is never fired.
I'm aware of image caching issues, but I can't get even one image, not mentioning have it changed.
For sure there's a very simple explanation, but I'm fighting with this for 2 days now to no avail.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题可能是以下之一:
会话对象“selecteduser”中没有任何内容可能导致未设置 imageurl 属性。 (解决方案:调试代码以确认存在会话对象)
正在设置图像 url,但图像未更改,这可能是浏览器缓存的问题。 (解决方案:将当前日期时间附加到查询字符串参数列表中,以强制浏览器加载新图像)。
“showphoto.aspx”是一个页面而不是图像,因此它返回未转换为图像的 html 代码。 (解决方案:将此页面的内容类型属性更改为图像
I think the problem may be one of the following:
There is nothing in the session object "selecteduser" which might cause that the imageurl property not set. ( Resolution: debug your code to confirm that there is a session object )
The image url is being setted but the image is not changed which might be a problem of browser caching. (Resolution: Append the current date time to the list of query string parameters to force the browser to load the new image).
"showphoto.aspx" is a page and not an image so it return html code which is not translated to image. (Resolution:Change the content-type property of this page to be image