久久久久久久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 超時)
主站蜘蛛池模板: 色综合视频 | 韩国精品在线观看 | www.成人久久| 成人精品国产免费网站 | 一级在线观看 | 天天碰夜夜操 | 国产区在线 | 国产欧美视频一区 | 国产综合精品一区二区三区 | 国产精品视频网 | 欧美日韩精品免费 | 国产精品久久久久一区二区三区 | 国产一区二区三区在线 | 久久99国产精一区二区三区 | 精品国产乱码久久久久久88av | www亚洲精品 | 日韩电影在线 | 日本视频一区二区 | 99在线播放 | 51ⅴ精品国产91久久久久久 | 玖玖色在线视频 | 一区二区av | 亚洲午夜视频 | 日本激情一区二区 | 日韩视频在线观看一区二区 | 日韩视频一区 | 久久日韩粉嫩一区二区三区 | 亚洲国产精品视频一区 | 亚洲人成在线播放 | 中文字幕 在线观看 | 中文字幕精品一区二区三区精品 | 国产精品一二三区 | 人人天天操 | www.久久久.com| 91精品一区二区三区久久久久久 | 午夜在线视频一区二区三区 | 九九久久久 | 成人免费大片黄在线播放 | 99亚洲精品 | 欧美精品一区二区三区蜜桃视频 | 欧美freesex黑人又粗又大 |