我的网站上有以下代码:
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中使用查询字符串
发布评论