如何从 asp.net 中的服务器端方法返回 url?

发布于 2025-01-01 22:09:00 字数 466 浏览 4 评论 0原文

我们花了很多时间来解决这个简单的问题。我们有一个服务器端函数,可以为图像创建 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&amp;s=128&amp;s=identity&amp;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 技术交流群。

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

发布评论

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

评论(2

随心而道 2025-01-08 22:09:00

您只需在直接或在 GetURL 方法中访问页面。

ImageUrl= '<%= HttpServerUtility.Decode(GetURL(Eval("UserID").ToString())) %>'

You could just add a call to HttpServerUtility.Decode() either on the page directly or in the GetURL method.

ImageUrl= '<%= HttpServerUtility.Decode(GetURL(Eval("UserID").ToString())) %>'
长伴 2025-01-08 22:09:00

避免编码的一种方法是在后面的代码中分配图像 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);

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