1

I would like to keep the same server url. ex: 10.139.183.192 to all pages.

I don't want to show 10.139.183.192/Task/Create

The route must continues, when the user type on address bar. But I want to hide it.

I've been searching a lot about url rewrite, but I can't find a solution.

I've tried to change the Global asax, Register Routes, etc.

Shoud I change in the IIS Server or in the Application?

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}
2
  • It's not really possible to do this. How would the server know to route the request? Sure, you can write some custom routing to switch based on query params instead of URL segments (as below) - but what does that really get you? Just a bunch of buggy custom code probably... Maybe tell us why you are trying to hide the routing information. Commented Aug 8, 2017 at 18:38
  • What is the reason behind this desire to keep the same route all the time, if i may ask ? Technical or aesthetic ? Commented Aug 10, 2017 at 8:36

2 Answers 2

1

You can work all pages on Home Controller and return View depending the post, exemple:

public ActionResult Home()
{
    string page = Request["page"];
    switch (page)
    {
        case "Home":
            return View();
            break;
        case "Product":
            return View("Product");
            break;
        default:
            return View();
            break;
    }

    return View();
}

or

User accesses all controllers and you code JS to change URL, like this:

window.onload = function(){
    window.history.pushState("", "", "/");
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can only do that natively if you use a client side framework such a Angular.JS.

In C#.NET MVC5 only three ideas come to my mind.

  • Use AJAX to change the content of the page without going to an other page
  • Second, you use a home-made routing like @Rodolfo said
  • Third and last (this is the weirdest one), you call your pages not in GET but passing POST data (making a FORM for each link) so the base route can control the displayed content based on the form data. This allows you to always target the same URL 10.139.183.192, unlike the point just above where the URL would change (GET parameters).

Personally, I think that what you are trying to achieve should be done either with a dedicated client side frameworks (they were made for that, but it would be JavaScript, not C# I believe) or using the Ajax method.

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.