【问题标题】:parameterized routing not accepting the dot as parameter in web api routing参数化路由不接受点作为 web api 路由中的参数
【发布时间】:2018-08-09 11:51:50
【问题描述】:

我正在为我的 web api 调用使用参数化路由。它适用于除点以外的所有特殊字符。 我试过的代码

 [HttpGet]
    [Route(@"TestMethod/{strvalue:regex((?s).*)}")]
 public IHttpActionResult TestMethod(string strvalue)
    {
        try
        {
           // logic
        }
        catch (Exception ex)
        {
            return Content(HttpStatusCode.BadRequest, "Error details:" + ex.Message);
        }
    }

当我传递参数值 dot(.) 时,它不接受请求。得到响应为

 Request URL
 http://localhost:64515/TestMethod/.

 Response: 
 {
"Message": "The requested resource does not support http method 'GET'."
}

预期结果:即使我传递了任何字符,例如 #,.%$@#&*,该请求也应该被接受

【问题讨论】:

    标签: c# asp.net .net asp.net-mvc asp.net-web-api


    【解决方案1】:

    您的 web.config 中的以下代码应该可以解决您的问题:

    <configuration>
        <system.webServer>
            <modules runAllManagedModulesForAllRequests="true" />
    

    【讨论】:

    • 试试这个
    • 不工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-12
    • 1970-01-01
    • 2015-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多