如何在virtua lpath中使用查询字符串

编程入门 行业动态 更新时间:2024-10-24 20:20:54
本文介绍了如何在virtua lpath中使用查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的网站上有以下代码:

I have the following code on my site:

<a href='<%# VirtualPathUtility.ToAbsolute("~/Products.aspx?category="+Eval("category")) %>'> <img src='<%# "/Store/Images/Thumbs/"+ Eval("CategoryImage") %>' /></a>

显示数据库中各种类别的imags。当用户点击图像时,我希望重定向到产品页面,显示所选类别的产品。 在visual studio上的localhost上工作正常但是当我将它上传到服务器,我得到错误'〜/ Products.aspx?category = selectedcategory'不是有效的虚拟路径。 我试过用'/ Products.aspx'和'Products.aspx'代替'〜/ Products.aspx',但我得到了同样的错误。

This displays imags for various categories in a database. When a user clicks on the image, i expect a redirect to products page which displays products for the selected category. It works fine on localhost on visual studio but when i uplaod it to server, I get the error that '~/Products.aspx?category=selectedcategory' is not a valid virtual path. I have tried using '/Products.aspx' and 'Products.aspx' in place of '~/Products.aspx' but i get the same error.

推荐答案

尝试移动查询字符串在$ code> ToAbsolute 之外调用: Try moving the query-string outside of the ToAbsolute call: VirtualPathUtility.ToAbsolute("~/Products.aspx") + Eval("category", "?category={0}")

此代码在本地计算机上运行但在服务器上运行的原因我最有可能的是它在本地配置为.NET 4.0应用程序,但在服务器上配置为.NET 2.0 / 3.5应用程序。如特定于版本的MSDN页面上的社区评论 [ ^ ],此方法的.NET 2.0版本错误地将?视为无效字符。

The reason this code works on your local machine but not on the server is most likely that it's configured as a .NET 4.0 application locally, but a .NET 2.0 / 3.5 application on the server. As mentioned in the Community Comments on the version-specific MSDN page[^], the .NET 2.0 version of this method incorrectly treated ? as an invalid character.

更多推荐

如何在virtua lpath中使用查询字符串

本文发布于:2023-10-27 02:55:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1532101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   如何在   virtua   lpath

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!