Asp.net 潜在危险的请求。在asp mvc中从客户端(?)检测到路径值

Asp.net 潜在危险的请求。在asp mvc中从客户端(?)检测到路径值,asp.net,asp.net-mvc,Asp.net,Asp.net Mvc,我在SO中看到过类似的问题,我试过,但不知道为什么它不符合我的要求 我在网站上看到这个错误,实际上我们的网站是这样工作的,当用户点击我们网站上的一个产品时,我们会将他们重定向到另一个网站 在sql db中,列站点是这样存储的:http://another.com/ 所以,当用户点击我们网站上的按钮时,效果很好,他被重定向到另一个网站 但当我将sql db中的站点列更改为http://another.com/GiftPack/PackageDetail?packageid=41 我在我们的网站上发

我在SO中看到过类似的问题,我试过,但不知道为什么它不符合我的要求

我在网站上看到这个错误,实际上我们的网站是这样工作的,当用户点击我们网站上的一个产品时,我们会将他们重定向到另一个网站

在sql db中,列站点是这样存储的:
http://another.com/

所以,当用户点击我们网站上的按钮时,效果很好,他被重定向到另一个网站

但当我将sql db中的站点列更改为
http://another.com/GiftPack/PackageDetail?packageid=41

我在我们的网站上发现了以下url错误

http://oursite.com/Product/90/httpcolonslashslashanotherdotscom/GiftPack/PackageDetail%3fpackageid%3d41

这是我迄今为止尝试过的:

[HttpPost]
[ValidateInput(false)]
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", ".")
.Replace("%3D", "=").Replace("%3F", "?").Replace("slash", "/"));
}
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", 
".").Replace("slash", "/").Replace("ques", "?").Replace("equal", "="));
}
<a target="_blank" class="btn btn-sm" href="@Url.Action("Product/" + pro.prodid
+ "/" + pro.site.Replace(".", "dots").Replace(":", "colon").Replace("//", "slashslash")
.Replace("=", "equal").Replace("?", "ques").Replace("/","slash"))">
Click to Go</a>
从和

在控制器中:

[HttpPost]
[ValidateInput(false)]
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", ".")
.Replace("%3D", "=").Replace("%3F", "?").Replace("slash", "/"));
}
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", 
".").Replace("slash", "/").Replace("ques", "?").Replace("equal", "="));
}
<a target="_blank" class="btn btn-sm" href="@Url.Action("Product/" + pro.prodid
+ "/" + pro.site.Replace(".", "dots").Replace(":", "colon").Replace("//", "slashslash")
.Replace("=", "equal").Replace("?", "ques").Replace("/","slash"))">
Click to Go</a>
在web.config中

 <httpRuntime targetFramework="4.5" requestValidationMode="2.0" 
 requestPathInvalidCharacters="*,:,&amp;,\,?,=" relaxedUrlToFileSystemMapping="true"/>


请允许我知道我做错了什么,任何帮助都会很好。

最后,使用该方法对我有效

在控制器中:

[HttpPost]
[ValidateInput(false)]
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", ".")
.Replace("%3D", "=").Replace("%3F", "?").Replace("slash", "/"));
}
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", 
".").Replace("slash", "/").Replace("ques", "?").Replace("equal", "="));
}
<a target="_blank" class="btn btn-sm" href="@Url.Action("Product/" + pro.prodid
+ "/" + pro.site.Replace(".", "dots").Replace(":", "colon").Replace("//", "slashslash")
.Replace("=", "equal").Replace("?", "ques").Replace("/","slash"))">
Click to Go</a>
视图中:

[HttpPost]
[ValidateInput(false)]
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", ".")
.Replace("%3D", "=").Replace("%3F", "?").Replace("slash", "/"));
}
public ActionResult Product(int prodid, string site)
{
return Redirect(site.Replace("colon", ":").Replace("slashslash", "//").Replace("dots", 
".").Replace("slash", "/").Replace("ques", "?").Replace("equal", "="));
}
<a target="_blank" class="btn btn-sm" href="@Url.Action("Product/" + pro.prodid
+ "/" + pro.site.Replace(".", "dots").Replace(":", "colon").Replace("//", "slashslash")
.Replace("=", "equal").Replace("?", "ques").Replace("/","slash"))">
Click to Go</a>

注意:pro是我的
foreach
循环中的元素名称

更多信息,请查看


希望这对其他人有所帮助。

我在类中的模型属性中尝试了
[allowtml]
,但仍然存在与
相同的错误:
我使用url重新编写
?,=,/
更新了返回重定向,从中,有人知道吗?我从未见过.NET html编码
http://
httpcolonslash
。这是从哪里来的?@Tommy,我刚刚替换了
/
,您可以检查
返回重定向
它对“”有效,但对
http://another.com/GiftPack/PackageDetail?packageid=41
它给出了错误,希望您阅读了我的问题我确实阅读了您的问题。我还是不明白这个
http://another.com/GiftPack/PackageDetail?packageid=41
正在变成此
httpcolonslashshanotherdotscom/GiftPack/PackageDetail%3fpackageid%3d41
。另外,为了回答您的问题,因为您要将产品id发送到action方法中,所以只需拉取产品的DB记录并从该方法重定向到产品URL即可。你不再在URL上做一些奇怪的翻译了。