I’ve got an ASP.NET MVC 3 web application that lives on server 1:
And i’ve got a widget (also ASP.NET MVC 3 web application) that lives on server 2:
Now, i want to generate a link to the main website from my widget.
So if i do something like this in the widget project:
@Html.RouteLink("Outbound link", "MainWebsiteRoute", "http", "http://www.mysite.com", string.Empty, null)
It will error (or generate the wrong link) because the route tables are different between the widget and website project.
Even if i copy the route from the main website into the widget one, the controllers/actions don’t exist in the widget project, so it won’t work.
How do i do it? Do i have to hardcode the URL’s?
Ended up duping the routes from the main website that i need in the widget.
Example route in main website:
Duped route in widget:
Notice how there are no route defaults – that’s because i don’t care, since that’s concerning matching the route to a controller/action. But this happens in the website, not the widget. All i’m concerned about is generating the URL.
I then created a simple wrapper for
RouteLinkcalledOutboundRouteLinkwhich specifies the hostname (for the main website), and generates the link.I don’t think it’s too bad a solution. Obviously, it’s hard-coded in a way – if the routes change in the main website then i’ll have to change the widget routes. But that fine, because if one of my URL’s changed, i’d have to do 301’s anyway, so the old URL’s would still work for the widget (they would get 301’d).
Also, i could go one step further and store the route url in a config file and share that between the projects, which would give me a bit more safety. But there’s only around 3 outbound URL’s so this should be fine.
Not saying this is the best way to handle it, but im happy with it.