A specific page in my web application has a URL www.example.com/Test/Index
However, I want to make this URL accessible when the user simply inputs www.example.com/Test instead of the whole thing.
So how can this be done using C# alone? Any help will be highly appreciated!
You can use a redirect. In ASP.NET this is Response.Redirect. In MVC this is RedirectToAction(“Index”). This will cause their browser to then request the other URL.
If you want the URL to not be changed/redirected, and show
www.example.com/Test, then you can use a server side redirect. ASP.NET: Server.Transfer. In MVC you can justreturn Index();but this can be problematic sometimes. A better option is to use a default route:You should get this code automatically with any newly created MVC 3 application. you just have to custimize it for the controller you want to respect this default route.