Can you register a controller against multiple URLs in asp.net mvc? - asp.net-mvc-2

I want to create an MVC application where by I can create areas of a site that use the same functionality but work under a seperate URL. e.g.
I want to use the same image gallery controller (type not instance) under two different URLs "/Event1/Gallery" and "ProductInformation/Gallery". However if I register this in the routes table and use the html helpers to create links would use the first registration found in the routes table as the link rather than being the actual URL that the controller is serving out at the time.
My questions are:
Is this the correct approach? If not what would be the better solution.
If it is the correct approach how do you stop the helpers from using the first registered controller name rather than the page it is on?
Thanks

Could you use named routes. That way you specify the route name instead of action, controller using the url helper and create the links yourself. Or you could create your own helper method to encapsulate each link.

Related

Scala-Play: How to dynamically generate a view?

For a Web Service framework I am currently working on I'd like to add the possibility to test the generic Json services based on their metadata. It should be possible to dynamically build a view to let users test available Web Services. Is there a provision or some supported way to generate views dynamically in Play? if not and supposing that I simply make a template and generate it on the fly, how can this view be injected into the application at runtime?
I will be happy to see documentation/examples/pointers that could help develop such solution ...
I am assuming that you want to create a scala.html and use it on somewhere by taking the html created, is that?
If you create a scala template myView.scala.html then on MyController you can call views.html.myView.render().body(); Then you would have the html created by the template.
Template Documentation

Zend_Route on the fly

We are developing a CMS. This will have a template system, so for example, if the admin wants to add a news section, then he will have to create a template for that section, and another one for each news, that is, for instance, /news/:int:/:title:/, but that route will be stored at the database... how can I do it?
You could use a common controller as a fallback route so that it catches all routes that the admin might create. This controller then goes on to read the appropriate template and show the data.

how to change zend controller names gracefully

I currently have a broken site structure that needs repair and I want to do it without doing much damage to whatever little SEO we have currently.
What I have is .com/doctor/office/route/values/here
What I want is .com/doctors/route/values/here
I'm guessing I can just set up a "doctor" controller to redirect all traffic to a "doctors" controller, but I need to make sure that the route values come across properly. I want to make sure it's a 301 to update all of my indexed pages.
Is there something built into Zend to do this easily? Or am I going to have to hack something nasty?
Seems like there are essentially two requirements:
Old urls get redirected to new urls.
New urls get handled by old controllers.
So:
Create a DoctorRedirectController with redirectAction()
Reroute the old urls to the redirectAction(). If you were using default routes before, then add a custom route that maps your old pattern to this new redirectAction. If you were already using custom routes, then just point them to this new redirect controller.
The redirectAction() builds the corresponding new url and does a 301-redirect.
Add routes that map the new urls to the old controller/actions.
No Zend magic, just the grunty work of remapping.

Why no Zend_Layout helper or codebehind? And best way to

I was just wondering why no code-behind or helpers were made to work with layouts? I have stuff I want to display in my layouts without having to set it up in a placeholder for every single controller.
I was also wanted to know what is the best way to persist a display-once "success-message" across many pages. For example, a user fills out a form and when it is submitted correctly they are redirected to another page. I want the user to see a success message on that other page. Is there some sort of provision in Zend Framework that makes this easier?
Well for the messages you can use the Flash Messenger helper
As far as setting up the place holders you could use a base controller and set these up in the init method overriding on descendents when necessary.

Defining External Url for Url.Content()

Is there any way to alter the behavior of Url.Content rendering mechanism so that my static content in the page is loaded from an external server?
To explain further, suppose you have an ASP.NET MVC 2 website, http://www.example.com and at some point, your want your static content to be loaded from static.example.com . But you have coded your application with syntax like Url.Content("~/Content/images/a.gif"). From that point, is there some configuration change within the ASP.NET MVC to render these URL's as "http://static.example.com/Content/images/a.gif"?
Thanks in advance.
Unforunately there is no such configuration setting. Your best approach would be to write your own helper extension method hanging off of UrlHelper that you control.