这只是一个为什么问题,因为它可能是一个错误的概念:(
以下是 ASP.net Web Api 项目中默认的 Web API 配置
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
}
我尝试改变
api / {controller} / {id}
到
# / {controller} / {id}
不工作,雄心勃勃的部分是它被忽略(NO 404),就像我正在路由到我的主页页面一样,然而其他消费完全像
- / {controller} / {id}
似乎是编码问题,概念缺失部分,有帮助吗?
最佳答案
#
是错误的选择。此部分仅与客户端相关,并且允许滚动到名称等于哈希后部分的元素
检查这个答案: https://stackoverflow.com/a/967659/1679310
摘录:
... I am afraid not, since the hash (the string including the #) never gets passed to the server, it is solely a behavioural property of the browser. The $_SERVER['REQUEST_URI'] variable will contain the rest however.
因此,虽然 #
之后的部分(包括)永远不会发送到服务器,但您不能将其用作路由的一部分
关于asp.net-mvc - 将 {api} 更改为 {#} ASP.net Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14869142/