且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

属性与路由多项领先零小数

更新时间:2023-02-25 21:12:03

的问题是,在URL中。

在默认情况下,如果是present的 StaticFileHandler 处理请求并查找一个文件名匹配的文件系统上的路径。要覆盖此行为,您可以指定一个处理程序,你要使用的URL。例如,添加以下到你的web.config:

 < system.webServer>
<&处理GT;
  <添加名称=UrlRoutingHandler路径=/ EvaluatorSetup / *动词=GETTYPE =System.Web.Routing.UrlRoutingHandler/>
< /处理器>
< /system.webServer>

将迫使任何要求开始与 / EvaluatorSetup / 使用 UrlRoutingHandler (与MVC路线相关的处理程序)

**解决方案**补充

我发现这个解决方案工作时,我还增加了以下内容web.config中的httpRuntime元素:

 <&的System.Web GT;
    <的httpRuntime relaxedUrlToFileSystemMapping =真/>
< /system.web>

Current ActionResult:

[Route("EvaluatorSetup/{evalYear}/{department}")]
public ActionResult RoutedEvaluatorSetup(int evalYear, string department)
{
    return EvaluatorSetup((int?)evalYear, department);
}

I would like to use the url:

/EvaluatorSetup/2014/001.3244

where the {department} is a ultimately a string, however, the routing is not picking up {department} as a string.

A. I don't know what type MVC is expecting for "001.3244", or what it is picking it up as.

B. I want to maintain it as a string with optional leading zeros, as in the example.

What am I doing wrong?

Update:

What I mean is, when I put a break in my code at the return line, it never fires.

/EvaluatorSetup/2014/foobar (WORKS!)

/EvaluatorSetup/2014/001.3244 (DOESN'T WORK!)

This leads me to believe that my routing is not correct:

[Route("EvaluatorSetup/{evalYear}/{department}")]

Specifically, it doesn't seem that 001.3244 is a valid string. So my question is how do I correct this:

[Route("EvaluatorSetup/{evalYear}/{department}")]
public ActionResult RoutedEvaluatorSetup(int evalYear, string department)

so that I can enter a uri:

/EvaluatorSetup/2014/001.3244

preferably where the leading zeros are maintained.

I thought about something like this:

[Route("EvaluatorSetup/{evalYear}/{corporation}.{department}")]

however, that is a guess. I don't even know if that is valid.

Additional Update:

the old route in the RouteConfig.cs (which doesn't seem to work anymore) is this:

routes.MapRoute(
    "evaluations_evaluatorsetupget",
    "evaluations/evaluatorsetup/{evalyear}/{department}",
    new { controller = "evaluations", action = "evaluatorsetup", evalyear = @"^(\d{4})$", department = @"^(\d{3}\.\d{4})$" },
    new { evalyear = @"^(\d{4})$", department = @"^(\d{3}\.\d{4})$" }
    );

The issue is the . in the URL.

By default, if a . is present the StaticFileHandler handles the request and looks for a filename matching the path on the file system. To override this behavior, you can assign a handler to a URL you are trying to use. For example, adding the following to your web.config:

<system.webServer>
<handlers>
  <add name="UrlRoutingHandler" path="/EvaluatorSetup/*" verb="GET" type="System.Web.Routing.UrlRoutingHandler" />
</handlers>
</system.webServer>

will force any request starting with /EvaluatorSetup/ to use the UrlRoutingHandler (the handler associated with MVC routes).

** Solution Supplement **

I found that this solution worked when I ALSO added the following to the httpRuntime element in web.config:

<system.web> 
    <httpRuntime relaxedUrlToFileSystemMapping="true" />
</system.web>