0

I have an asp.net application where I need to have a general route for given Medical Specialties to route to a given page except for one which I want to route to a different page.

For example I want /Specialties/Allergy, /Specialties/Nutrition to all route to a given page like they currently do. The part I can't figure out is I want the URL to still show /Specialties/Urology but have urology rout to a different page because it is becoming essentially it own subsite where the other ones are not.

I'm sure I need to add a Route constraint but I can't seem to figure out how to accomplish that.

I have include all of the relevant code I currently use for the general route.

private static void AddEntityRoute(string name, string url, string path, string dir)
{
((List<string>)HttpContext.Current.Application["RouteList"]).Add(url);

RouteTable.Routes.Add(name,
 new Route(url, new EntityRouteHandler(path, dir)));
}

public class EntityRouteHandler : IRouteHandler
{
    string _virtualPath;
    private readonly string baseDir;

    public EntityRouteHandler(string virtualPath, string baseDir)
    {
        _virtualPath = virtualPath;
        this.baseDir = baseDir;
    }

    public IHttpHandler GetHttpHandler(RequestContext requestContext)
    {
        var display = BuildManager.CreateInstanceFromVirtualPath(
                        _virtualPath, typeof (Page)) as IEntityDisplay;

        display.FriendlyURL = baseDir + requestContext.RouteData.Values["name"];
        return display;
    }
}

AddEntityRoute("Specialties", "Specialties/{name}", "~/SpecialtyDisplay.aspx", "/Specialties/");

1 Answer 1

1

You're approaching this the wrong way.

If your intention is to direct a specific url to a different controller/action, then just add another route.

routes.MapRoute("", "Specialties/Urology", new { controller = "someothercontroller", action = "someotheraction" });
routes.MapRoute("", "Specialties/{speciality}", new { controller = "specialities", action = "show" });

Here a request to "Specialities/Urology" would match the first route. A request to "Specialities/Allergy" would match the second.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.