【问题标题】:ASP.Net MVC 5 Routing wildcard + querystringASP.Net MVC 5 路由通配符 + 查询字符串
【发布时间】:2016-06-11 10:52:27
【问题描述】:

我正在使用这个路由过滤器

[Route("search/{*segments}")]

这需要我提供的所有细分,可能很多。

这是一个例子

http://localhost:50877/search/c_50_showcases%5E-displays/a_brand-name:33113319_balt:1623762%7Cmooreco:1672386/a_total-number-of-shelves:33111115429_5:3138:lt/so_ts

现在我还需要这条路线的查询字符串,但我无法让它工作。

http://localhost:50877/search/?query=HP%20DesignJet&items=HEW51645A|ELI75220

它给了我403 错误。

Web 服务器配置为不列出该目录的内容

如何创建可以采用通配符和查询字符串的路由来处理传入请求。我一定会在Route 中使用search

我也试过这个

http://localhost:50877/search/test?query=HP%20DesignJet&items=HEW51645A|ELI75220

它有效,但这会影响 SEO。

【问题讨论】:

标签: asp.net asp.net-mvc-5 asp.net-mvc-routing


【解决方案1】:

以这种方式定义动作和路线:

[System.Web.Mvc.Route("search/{*segments}")]
public ActionResult Search(string segments, string query, string items)

允许获取通配符(在段变量中)以及查询字符串参数(查询和项目)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-01
    • 2020-12-28
    • 1970-01-01
    • 2012-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多