ASP.NET MVC:如何使用 .(期间)结束

ASP.NET MVC: How to Route Search Term with . (Period) at the end(ASP.NET MVC:如何使用 .(期间)结束)
本文介绍了ASP.NET MVC:如何使用 .(期间)结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我尝试发出搜索词以 .(句点)结尾的请求时,我从 .Net MVC 收到 404 响应.这是我正在使用的路线:

I get a 404 response from .Net MVC when I try to make a request where my search term ends with a . (period). This is the route that I'm using:

routes.MapRoute(
                "Json",
                "Remote.mvc/{action}/{searchTerm}/{count}",
                new { controller="Remote", count=10}
            );

在搜索词中带有 . 的搜索工作正常,只是不能以它结束.有关如何路由此搜索请求的任何想法?

The search works fine with a . inside the search term, it just cannot end with it. Any thoughts on how to route this search request?

推荐答案

我已经解决了一个类似的问题(我遇到了/music/R.E.M. 之类的路径问题)我在 system.webServer/handlers 部分添加了以下行(根据您的情况进行了调整):

I have solved a similar issue (I had trouble with paths like /music/R.E.M.) I've added the following line into the system.webServer/handlers section (adjusted for your case):

 <add name="UrlRoutingHandler" type="System.Web.Routing.UrlRoutingHandler, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" path="Remote.mvc/*" verb="GET"/>

我也注意到了,

<httpRuntime relaxedUrlToFileSystemMapping="true" />

仅当句点 (.) 位于斜杠中间的某处时才有效(例如/abc/de/f),并且当句点看起来像文件类型分隔符时无效(例如/abc/de/fg).

does work only if the period (.) is somewhere in the middle pair of slashes (e.g. /abc/d.e/f) and does not work when the period looks like a file type separator (e.g. /abc/de/f.g).

这篇关于ASP.NET MVC:如何使用 .(期间)结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

The reference assemblies for framework .NETCore, Version=v5.0 were not found(未找到框架 .NETCore,Version=v5.0 的参考程序集)
Good-practices: How to reuse .csproj and .sln files to create your MSBuild script for CI?(良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 MSBuild 脚本?)
Run an MSBuild target only if project is actually built(仅在实际构建项目时运行 MSBuild 目标)
Build project with Microsoft.Build API(使用 Microsoft.Build API 构建项目)
Add a msbuild task that runs after building a .NET Core project in Visual Studio 2017 RC(添加在 Visual Studio 2017 RC 中构建 .NET Core 项目后运行的 msbuild 任务)
Assembly binding error when building Office add-in: quot;FindRibbonsquot; task failed unexpectedly(构建 Office 加载项时的程序集绑定错误:“FindRibbons任务意外失败)