Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6141571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:16:07+00:00 2026-05-23T18:16:07+00:00

Note : Below is just a small demo sort to simulate what i am

  • 0

Note: Below is just a small demo sort to simulate what i am looking for:

Below are the urls format on my app that user can see

mydomain.com/cat/1  --display cat with id 1 |controller=Cat, action=DisplayDetails
mydomain.com/dog/2  --display dog with id 2 |controller=Dog, action=DisplayDetails
mydomain.com/cow/2 --display cow with id 3  |controller=Cow, action=DisplayDetails

I have maintained a system where no 2 animals(may be of different kind) can have same id, it means if there is a cat with id=1, we cant have any other animal with that id. Also from my system i can extract animal details+ type just from animal id

Apart from existing URL pattern, I am planning to create a short Url in format as below

mydomain.com/1  --this will show cat
mydomain.com/2  --this will show dog
mydomain.com/3  --this will show cow

Routes i have created are as below, and they appear same order in global.asax

pattern= Cat/{id}, controller= Cat, action=DisplayDetails
pattern= Dog/{id}, controller= Dog, action=DisplayDetails
pattern= Cow/{id}, controller= Cow, action=DisplayDetails
pattern= {id}, controller= DisplayAnyAnimal ----------i want help in this Route

Currently Controller looks like this

public class DisplayAnyAnimalContoller : Controller
{
      public ActionResult Index(string animalId)
      {
           //iam processing request here from animalId
           //now i know which contoller+action needs to be executed

          //say for instant i have to display dog with id=2

          //currently iam doing this to redirect and its working fine, 
          //but it changes url
          -----------------------------------------------
          #########################
          ### i need help here  ###       
          #########################
         return RedirectToRoute(new {contoller="Dog",action="DisplayDetails",id=2 });             
          -----------------------------------------------
      }
}

Now the problem with RedirectToRoute / RedirectToAction is they both changes the URL. But i dont want to change my url pattern.

Please suggest me how to achieve this, you may suggest some entirely different way, to achieve this

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T18:16:08+00:00Added an answer on May 23, 2026 at 6:16 pm

    You could write a custom animal route:

    public class AnimalRoute : Route
    {
        public AnimalRoute(string url, IRouteHandler routeHandler)
            : base(url, routeHandler)
        { }
    
        public override RouteData GetRouteData(HttpContextBase httpContext)
        {
            var rd = base.GetRouteData(httpContext);
            var id = rd.GetRequiredString("id");
    
            // TODO: Given the id decide which controller to choose:
            // you could query the database or whatever it is needed.
            // Basically that will be the code you had in the beginning
            // of the index action of your DisplayAnyAnimalContoller which
            // is no longer needed.
            if (id == "1")
            {
                rd.Values["controller"] = "Cat";
            }
            else if (id == "2")
            {
                rd.Values["controller"] = "Dog";
            }
            else if (id == "3")
            {
                rd.Values["controller"] = "Cow";
            }
            else
            {
                // no idea what this animal was
                throw new HttpException(404, "Not found");
            }
            rd.Values["action"] = "index";
            return rd;
        }
    }
    

    and then register it in Global.asax:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.Add(new AnimalRoute("{id}", new MvcRouteHandler()));
    }
    

    Now when you navigate to mydomain.com/1, the GetRouteData method of the custom route will be executed, will fetch the id=1, and then it will use the Index action of the Cat controller.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm just starting out on my first 'real' cocoa app. Note that this is
Note: Please note that the code below is essentially non-sense, and just for illustration
I know that Tkinter is just a thin layer over Tcl/Tk. Tkinter you can
Note: the below code is just for demonstration and I am using jQuery and
When I run the following code, I get the exception below: ''# NOTE: ExcelApp
Note The question below was asked in 2008 about some code from 2003. As
Note my code below. I am trying to figure out why my data is
Note the comment below. It cannot compiled on UVA because of a bug in
Please note the Edit below for a lot more information, and a possible solution
Please note: In each step I describe below I'm logged in as the same

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.