I have implemented URL routing in ASP.NET 4.0 using following route.
routes.MapPageRoute(
"NewsDetails", // Route name
"news/{i}/{*n}", // Route URL
"~/newsdetails.aspx" // Web page to handle route
);
which gives me url like
http://www.mysie.com/news/1/this-is-test-news
and this is working in my localhost fine.
But when I uploaded it on the server it gives ...
Server Error
404 - File or directory not found.
The resource you are looking for might have been removed, had its name changed,
or is temporarily unavailable.
If I try http://www.mysie.com/news/1/this-is-test-news.aspx then it displays page.
Has anyone have same problem?
How can i set URL http://www.mysie.com/news/1/this-is-test-news to work on windows server 2008 ?
To enable default ASP.Net 4.0 routing with IIS 7.5:
web.config
with the code below
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<remove name="UrlRoutingModule"/>
<add name="UrlRoutingModule"
type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler"
preCondition="integratedMode"
verb="*"
path="UrlRouting.axd"
type="System.Web.HttpForbiddenHandler, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>
3. Create Routes in your global.asax
file
Note: You have to set Application Pool to Asp.net 4.0 application pool , as routing is not working with Asp.net 4.0 Classic Application pool.
Hope this will help.