如何在virtua lpath中使用查询字符串 [英] How do I use a query string in virtua lpath

查看:70
本文介绍了如何在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中使用查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆