I am developing group feature on asp.net application. I want to give users direct access to groups, so I want the url to be
www.<domain>.com/<groupname>
I implemented URL Routing for this case, but the problem that I want to pass the group name an to asp page as parameter, how can I do that?
the actual path is "~/Public/ViewGroup?group=<groupname>
, how to get this group name and add it to the virtual path?
Thanks
ASP.NET MVC path style arguments (parameters) can be accessed in C# controller like so. Path argument to be retrieved is "id" which returns a value of "123".
MVC Routing
MyController.cs
The quick answer is use:
And then instead of (or as well as) using
querystring
to extract the value in~/public/viewgroup
code, you would instead extract the groupname fromRouteData
as follows.The other option is use the IIS rewrite module.
If you really must pass the value as a new
querystring
value, and want to use Routing, then things get tricky. You actually have to define a custom handler and rewrite the path in order to append the routing values to thequerystring
.This can be registered as follows:
It's quite a lot of work to avoid just pulling the value out to the Routing data.