如何从 asp.net 中的服务器端方法返回 url?
我们花了很多时间来解决这个简单的问题。我们有一个服务器端函数,可以为图像创建 URL(类似于头像标识),但它的输出是 html 端编码的,这可能会导致一些问题。
...
<asp:image ID="Image1" runat="server" ToolTip='<%# Eval("UserID") %>' ImageUrl= '<%= GetURL(Eval("UserID").ToString()) %>'></asp:image>
...
我们最终得到:
<img id="Image1" title="123456789" src=""http://www.ourwebsite.com/image/123456789&s=128&s=identity&p=userid"/>
Simple question that we've spent to much time on. We have a server side function that creates a URL for an image (similar to a gravatar identicon), but it's output is being html endcoded, which is probably causing a few issues.
...
<asp:image ID="Image1" runat="server" ToolTip='<%# Eval("UserID") %>' ImageUrl= '<%= GetURL(Eval("UserID").ToString()) %>'></asp:image>
...
We end up with:
<img id="Image1" title="123456789" src=""http://www.ourwebsite.com/image/123456789&s=128&s=identity&p=userid"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需在直接或在
GetURL
方法中访问页面。You could just add a call to HttpServerUtility.Decode() either on the page directly or in the
GetURL
method.避免编码的一种方法是在后面的代码中分配图像 url,如下所示:
Image1.ImageUrl = GetURL(userId);
One way you can avoid encoding by assigning image url in the code behind like this:
Image1.ImageUrl = GetURL(userId);