Attribute routing with multiple leading null commas
Current ActionResult:
[Route("EvaluatorSetup/{evalYear}/{department}")]
public ActionResult RoutedEvaluatorSetup(int evalYear, string department)
{
return EvaluatorSetup((int?)evalYear, department);
}
I would like to use url:
/EvaluatorSetup/2014/001.3244
where {department} is ultimately a string, however, routing does not collect {department} as a string.
and. I don't know what type MVC expects for "001.3244", or what it picks up like.
Q. I want to store it as a string with optional leading zeros like in the example.
What am I doing wrong?
Update:
What I mean is when I put a break in my code on the back line it never fires.
/EvaluatorSetup/2014/foobar (WORKS!) /EvaluatorSetup/2014/001.3244 (DOESN'T WORK!)
This leads me to think that my routing is wrong:
[Route("EvaluatorSetup/{evalYear}/{department}")]
In particular, 001.3244 doesn't seem to be a valid string. So my question is how can I fix this:
[Route("EvaluatorSetup/{evalYear}/{department}")]
public ActionResult RoutedEvaluatorSetup(int evalYear, string department)
so that I can inject uri:
/EvaluatorSetup/2014/001.3244
preferably where leading zeros are supported.
I thought of something like this:
[Route("EvaluatorSetup/{evalYear}/{corporation}.{department}")]
However, this is an assumption. I don't even know if it really is.
Additional update:
old route in RouteConfig.cs (which doesn't work anymore):
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})$" }
);
source to share
The problem is in .
the URL.
By default, if present .
, StaticFileHandler
processes the request and looks for a file name that matches the path in the file system. To override this behavior, you can assign a handler to the 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/
use UrlRoutingHandler
(handler associated with MVC routes).
** Application to application **
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>
source to share