The default code that VS generates for HomeController is:
<HandleError()>
Public Class HomeController Inherits System.Web.Mvc.Controller
Function Index() As ActionResult
ViewData("Message") = "Welcome to ASP.NET MVC!"
Return View()
End Function
Function About() As ActionResult
Return View()
End Function
End Class
Let's say that I want to create a different URL for the about page without changing the method name. I've tried:
'
' GET: /Home/Aboutblah
But that doesn't work. When I go to http://localhost:1957/Aboutblah, I get a 404 from the ASP .NET server.
Consequently, I was wondering if the "GET " blob of text actually does anything and if it is possible to fiddle with URLs without diving into the ASAX file.
Also, you can decorate the method with an attribute:
[ActionName("Aboutblah")]
James
EDIT I just noticed you're using VB. You'll have to translate into VB, maybe:
<ActionName("Aboutblah")>
?
Also, yes, the comments, ie:
' Get /Home/Index
are just that -- comments.
You will need to modify the code that sets up the routes.
If it's just a one-off, you can set up a specific route for this url.
The following would explicitly map url "Home/aboutBlah" to action HomeController.About action and use the standard controller/action route url pattern for any other urls:
RouteTable.Routes.MapRoute("CustomAboutUrl", "Home/aboutBlah", new {controller = "Home", action = "About"});
RouteTable.Routes.MapRoute("Default", "{controller}/{action}");
Look into URL Routing, you should be able to define alternative URLs for the controller actions just fine. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With