0

I have a working ASP.NET MVC application to which I would like to add a very simple URL which I would like to be redirected to another URL, without the Controller part of the path in it.

I.e. I want to be able to tell people to go to mySite.org/Hello and have it direct them to mySite.org/Whatever/WhateverElse?myfun=9, or whatever.

So I added a method in PublicController that redirects Hello to whatever, which works, except it requires me to tell people to go to mySite.org/PUBLIC/Hello, and we'd like to not have the extra word "public" in there.

Hours of confusing study later, I see that I could perhaps add a line in Global.asax.cs such as: routes.MapRoute(name: "Hello", url: "Public/Whatever"); ... or something... but that actually changes the way everything gets routed, and after trying various syntactical variations, nothing has seemed to just change one basic address to map to another basic address.

Is there a simple way to get mySite.org/Hello to map to another URL, without the virtual subdirectory for the public controller?

1 Answer 1

2

Create a custom route (it would need to be the first route in the table)

routes.MapRoute(
  name: "Hello",
  url: "Hello",
  defaults: new { controller = "Whatever", action = "WhateverElse" }
);

then /Hello will redirect to /Whatever/WhateverElse

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

1 Comment

Aha! Thank you so much! I was so burnt out trying to figure out what was supposed to go where! This works. (I can/will mark accepted in 5 mins.)

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.