gpt4 book ai didi

asp.net-mvc - 带有 urlEncoded 部分的 WebApi 路由

转载 作者:行者123 更新时间:2023-12-02 00:08:27 24 4
gpt4 key购买 nike

我有路线:

config.Routes.MapHttpRoute(
name: "RestApi",
routeTemplate: "rest/{storage}/{controller}/{id}/{action}",
defaults: new
{
id = RouteParameter.Optional,
action = "Index"
}

{id} 参数可以是 URI 本身,我对其进行了编码。例如,路线可以是:/rest/main/nodes/http%3A%2F%2Fwww.company.com%2Fns%2FGeo%23United_States/rdf

但是这样错了,是行不通的。使用简单的 {id} 参数就可以了。

我应该怎么做才能让它发挥作用?

最佳答案

What I should do to make it works?

如果您打算向服务器发送任意字符,只需使用查询字符串参数:

/rest/main/nodes/rdf?url=http%3A%2F%2Fwww.company.com%2Fns%2FGeo%23United_States

您可以阅读 following blog post来自 Scott Hanselmann,他在其中介绍了在 url 的路径部分中使用此类值的困难。

我引用他的结论:

After ALL this effort to get crazy stuff in the Request Path, it's worth mentioning that simply keeping the values as a part of the Query String (remember WAY back at the beginning of this post?) is easier, cleaner, more flexible, and more secure.

关于asp.net-mvc - 带有 urlEncoded 部分的 WebApi 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16938887/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com