Chris Eigenheer
Chris Eigenheer

Reputation: 1

URL Routing Not Working (asp.net 4.5, webforms)

I've been trying to figure out how to get URL routing to work on my box all evening. I'm pretty sure I'm doing things according to the online tutorials (http://msdn.microsoft.com/en-us/library/vstudio/dd329551%28v=vs.100%29.aspx) but for some reason it's not working.

This is what I currently type in the address bar: /MA1/DoSurvey.aspx?id=42

But I want the URL to work like this: /MA1/DoSurvey/42

According to the tutorial I have to modify:

1: Global.asax.cs by adding

RouteConfig.RegisterRoutes(RouteTable.Routes);

into the Application_Start method

2: RouteConfig.cs by adding

routes.MapPageRoute("","DoSurvey/{id}","~/MA1/DoSurvey.aspx");

into the RegisterRoutes method

3: Add

using System.Web.Routing;

as a reference in the DoSurvey.aspx page and then

4: Grab the querystring variable by using

string SurveyIdQueryStringValue = Page.RouteData.Values["id"] as string;

in the DoSurvey.aspx page

what am I missing?

Upvotes: 0

Views: 757

Answers (1)

Mohammed Al-said
Mohammed Al-said

Reputation: 36

I Add this code to web.config and everything worked fine, try it

<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" />

Upvotes: 1

Related Questions