asp.net-mvc - 将 {api} 更改为 {#} ASP.net Web API

标签 asp.net-mvc asp.net-web-api

这只是一个为什么问题,因为它可能是一个错误的概念:(

以下是 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/

相关文章:

c# - ASP.NET MVC 5 身份 userManager.IsInRole

asp.net-mvc - 如何根据kendo ui mvc网格中的条件格式化行

asp.net-mvc - ASP.NET MVC 中的动态站点地图

asp.net - Web Api 帮助页面来自 1 个以上文件的 XML 注释

asp.net-mvc - Asp.net Mvc 4 和 Web Api 中的路由

c# - 仅当文件大时,使用 PostAsync 的 Web API 才会抛出异常

javascript - 在 ASP.NET MVC 中使用 ajax javascript 调用 View

c# - 是否将用户设置存储在 ASP.NET Core Identity AspNetUsers 表中

asp.net - 无法从 'System.Web.Mvc.ModelStateDictionary' 转换为 'Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary'

c# - 如何返回createatroute位置?