1

I want to know how to have something like this in the url in asp.net MVC

/Article/12.20.2013

I tried below and its working fine for /Article/12-20-2013 but not for /Article/12.20.2013. I have below in the Global.asax

routes.MapPageRoute("Blog", "/Article/{entryDate}", new {controller = "Article", action = "Entry")}; 

I also tried something like below

routes.MapPageRoute("Blog", "/Article/{month}.{Date}.{year}", new {controller = "Article", action = "Entry")}; 

but no luck..

Please guide me with some sample.

3
  • Any chance you are on IIS6? Commented Aug 9, 2013 at 5:09
  • You should consider using the first pattern /Article/12-20-2013 as your route as setting RunAllManagedModulesForAllRequests="true" is not advised as it adds extra overhead by running requests for static files like .html and .jpeg through the ASP.NET pipeline. See ASP.NET Routing Commented Sep 8, 2014 at 12:32
  • +1 I was not aware of that. Good to know that Thanks again Anthony Commented Sep 9, 2014 at 6:39

2 Answers 2

2

I believe the issue is that IIS might be treating ".2013" as a file extension and trying to find a handler for it. What we need to do is to have MVC process all requests.

If you are on IIS 6 this you will need to do a wildcard mapping to aspnet_isapi.dll. If you are on IIS 7 you can set the runAllManagedModulesForAllRequests="true":

<system.webServer> <modules runAllManagedModulesForAllRequests="true"> </modules> </system.webServer> 
Sign up to request clarification or add additional context in comments.

1 Comment

+1 for the answer. can you please tell if this can be done for a specific Controller Views ?
0

You need to change web.config to force every url starting with Article to be treated as a MVC url

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

Then your routing should be working fine.

1 Comment

Already done that but whenever i tried /Article/12.20.2013 it fails where as /Article/12-20-2013 worked fine

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.