久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

當 URL 中有尾隨空格時,WebAPI 路由 404

WebAPI route 404#39;s when there is a trailing space in the URL(當 URL 中有尾隨空格時,WebAPI 路由 404)
本文介紹了當 URL 中有尾隨空格時,WebAPI 路由 404的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

使用默認的 web api 路由

With the default web api route

config.Routes.MapHttpRoute(
            name: "API Default",
            routeTemplate: "api/{controller}/{id}",
            defaults: new
                      {
                          id = RouteParameter.Optional
                      }
            );

還有一個控制器

public class TestController : ApiController
{
    [HttpGet]
    public HttpResponseMessage Get(string id)
    {
        return Request.CreateResponse(HttpStatusCode.OK, id);
    }
}

'api/test/1'

返回 1

如果由于某種原因您向 'api/test/1%20' 發送請求

If for some reason you send a request to 'api/test/1%20'

404 路線.

現在這個例子可能看起來很傻,因為瀏覽器會修剪尾隨空格,但是

Now this example may seem silly since browsers trim trailing spaces, but

對于像 'api/{controller}/{id}/{extrastuff}'這樣的路由

'1 ' 中的空格將轉換為 '1%20' 并且請求將在找不到路由上出現 404.

the space in '1 ' would convert to '1%20' and the request will 404 on the route not being found.

推薦答案

您的問題與 WebAPI 本身無關,而是 Asp.Net 如何處理一些特定的 url.而 Asp.Net 以非常偏執的方式處理這些 url,因此您需要告訴它 放松.

Your issue has nothing to do with WebAPI itself but how Asp.Net handles some specific urls. And Asp.Net handles these urls in a very paranoid way, so you need to tell it to relax.

system.web 下將此行添加到您的 web.config:

Add this line to your web.config under system.web:

<httpRuntime relaxedUrlToFileSystemMapping="true" />

您可以閱讀有關此主題的更多信息:

You can read more about this topic:

  • 把騙局(COM1,LPT1,NUL 等)返回您的網址

同樣在 SO:

  • 找不到資源."有點"時出現錯誤;在網址的末尾
  • URL 以 %20 結尾的問題(它描述了不同的上下文,所以我不認為這是一個真正的重復)
  • "The resource cannot be found." error when there is a "dot" at the end of the url
  • Problem with a URL that ends with %20 (it describes a different context so I don't think that this is a real duplicate)

這篇關于當 URL 中有尾隨空格時,WebAPI 路由 404的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

ASP.NET Core authenticating with Azure Active Directory and persisting custom Claims across requests(ASP.NET Core 使用 Azure Active Directory 進行身份驗證并跨請求保留自定義聲明)
ASP.NET Core 2.0 Web API Azure Ad v2 Token Authorization not working(ASP.NET Core 2.0 Web API Azure Ad v2 令牌授權不起作用)
ASP Core Azure Active Directory Login use roles(ASP Core Azure Active Directory 登錄使用角色)
How do I get Azure AD OAuth2 Access Token and Refresh token for Daemon or Server to C# ASP.NET Web API(如何獲取守護進程或服務器到 C# ASP.NET Web API 的 Azure AD OAuth2 訪問令牌和刷新令牌) - IT屋-程序員軟件開發技
.Net Core 2.0 - Get AAD access token to use with Microsoft Graph(.Net Core 2.0 - 獲取 AAD 訪問令牌以與 Microsoft Graph 一起使用)
Azure KeyVault Active Directory AcquireTokenAsync timeout when called asynchronously(異步調用時 Azure KeyVault Active Directory AcquireTokenAsync 超時)
主站蜘蛛池模板: 成人日韩精品 | 国产日本精品视频 | 日韩欧美在线视频 | 成人性生交大片免费看r链接 | 欧美日韩久久精品 | 综合久久99 | 欧美一级二级视频 | 在线免费黄色小视频 | 亚洲精品一区二区三区蜜桃久 | 91精品国产91久久久久久密臀 | 在线观看av网站永久 | 久久草在线视频 | 日韩中文一区二区三区 | 亚洲精品一区在线观看 | 天天草天天干天天 | 国产成人综合一区二区三区 | 午夜精品久久久久久久久久久久久 | 中文日韩在线 | 成人在线网 | 日本高清aⅴ毛片免费 | 一a级片| 婷婷福利 | 日本在线看片 | 国产色婷婷| 黄色精品| 日韩一区二区黄色片 | a在线视频观看 | 国产亚洲精品久久yy50 | 黄色毛片在线播放 | 中文字幕在线国产 | 日韩免费 | 久久性色 | 欧美一区二区三区久久精品 | 日本成人午夜影院 | 精品久久久久久国产 | 在线免费观看日本视频 | 亚洲欧美在线观看 | 免费在线一区二区 | 精品国产成人 | 一区免费 | 欧美在线一区二区三区 |