I have a web app, A, that has a virtual directory that is also an app, B. I've tried to create an MVC route in A such that the URL appears to be in the virtual directory but is still handled by A and not B. However, it seems to be being ignored. Is there a way of making the MVC route take priority over the virtual directory?
If you want App A to override App B, you're going to have to add some Url Rewriting configuration, not MVC routing logic, which, if you're using IIS7+ which, I believe, you should be set up in the web.config file for App A. IIS has to know which application to forward a request to; by the time MVC routing is invoked, the application has already been selected at that point (you cannot unselect B once the actual application is invoked * ). You also might be able to get away with setting up the url rewrite rules in App B to point to App A, but I'm not quite sure how that'd work.
Please note, what I'm saying about application invocation is very likely not strictly true. But to be honest, I don't know if I could give a completely accurate description of the lifecycle of a url rewritten request; I just hope I'm roughly approximating what happens in simplified terms. Just learn more about url rewriting in IIS and IIS7 request lifecycles visit the following links:
http://www.iis.net/learn/extensions/url-rewrite-module/using-the-url-rewrite-module
http://msdn.microsoft.com/en-us/library/bb470252(v=vs.100).aspx
So you got two apps A & B. You say you tried to create MVC route but in which app? If you can explain a bit more what you trying to achieve, it will be easier to answer.
ASP.net routes (also available in web forms) can take any form you want. The one thing you must keep in mind that the route maps are greedy. So if most generic route is found first it is not going to check anything below no matter what. So the order should be most specific and last one should be most general.
Check this post http://yogiorchard.azurewebsites.net/archiving-items-and-a-routing-lesson
Hope this helps
Related
I've added a second project to an existing solution and am running into a bit of an issue with routing requests.
When I initially add the second project, there is no problem with routing.
However, I have a DB Context in the original project that I'd like to use from the second. It is when I add the project reference that my issue manifests.
The issue is that I am getting ambiguous routing requests, so I need to find a way to distinguish requests, for example, to the Home Controller.
Be advised, I use attribute routing.
I've come up with a few workarounds:
Copy the DB Context into the second project. This has obvious shortcomings and is the least attractive solution, but it will work.
Set up routes with some distinguishing prefix, i.e. "/proj2Home", etc. While crude, this is the least objectionable and is straight-forward to implement. It does mandate a route value for every Url of the second project but I could hold my nose on that.
I've considered using Middleware but it looks like the error is coming from UseRouting() (although I'm not 100% on this) so I'm not sure what I can do at that point.
Does anyone know of some sort of build-in mechanism to accomplish this?
I've created an Orchard Website that consists of many mini-websites made operable via theme selection relating and triggered by the current [unique] URL all from the same DB.
It works as I'd hoped, but I wish to improve the Autoroute paths of my pages.
Currently I'm using:
{Content.Fields.PageOrderPart.SitesTaxonomy.Terms:0}/{Content.Slug}
Which results in:
www.site1.com/sitealpha/gallery
www.site2.com/sitebeta/gallery
What I would like is:
www.site1.com/gallery
www.site2.com/gallery
However, I still need to be able to differentiate pages with the same name [...hence why the Autoroute path above was created in the first place] - or I will obviously get permalink duplication errors.
Can anyone think of an ingenious way to sort this or is there some Orchard feature I may've missed, perhaps url rewrites or possibly an existing MVC method?
Many thanks for your input, PP
Further thoughts (hopefully this doesn’t influence any other member's sugestions):
Rewrite rules: Probably aren't dynamic enough for the amount of content I have [still increasing] - and I could see any alterations to existing permalinks being a real nightmare.
Besides, for an unkown reason - I and some other Orchard users - can't seem to get a rewrite action to work?
Routes: Honestly, I haven't played with these properly - I can see that capturing and dissecting a URL to stipulate the area / controller / action should be easy enough - but I'm not sure how to go about redirecting to a particular Orchard page?
FilterProvider, IActionFilter: I tested this scenario [which could become quite complicated code wise] and I'm not sure the performance is acceptable -- my dev system seems to really suffer with any code in the 'OnActionExecuting' method.
Update: I've investigated the IActionFilter scenario and it appears my initial performance worries were unfounded [i.e. a fresh install didn't behave any slower with some URL restructuring code on the 'OnActionExecuting' method].
My last hurdle is to discover why IIS Rewrite rules aren't working with Orchard:
https://stackoverflow.com/questions/35226580/orchard-cms-iis-rewrite-rules-do-not-work-for-rewrite-action-types
It could be that multi tenancy would be the feature you are after. You can have one code, one db but they are all completely separate sites. So separate admin areas etc.
http://docs.orchardproject.net/Documentation/Setting-up-a-multi-tenant-orchard-site
I've created three related ASP.NET MVC web-applications that sit in IIS like so:
root
|-Emailing
|-InternalManagement
Where the root site is customer facing.
The three sites have different security requirements and I wanted to be able to modify one application with less worry about breaking the other two.
However both the root and the internal management site need to have links to the emailing site.
I'm using T4MVC.
Now I've separated the T4MVC helpers for each project by modifying the HelpersPrefix, and root and InternalManagement reference emailing so for example I can do something like:
Url.Action(MVCEmailing.CustomerDocuments.Index())
Which almost works - except the actual URL produced will be:
For the root application:
http://mydomain.com/CustomerDocuments/Index
for the internal management application:
http://mydomain.com/internalManagement/CustomerDocuments/Index
What I need in both cases is for the URL produced to look like so:
http://mydomain.com/emailing/CustomerDocuments/Index
What's the best way to go about doing this?
Copying from the T4MVC doc:
One key concept to understand about T4MVC is that it is just a thin
layer over MVC. e.g. while it provides strong typing, in the end it's
just putting values in a dictionary, and using standard MVC to
generate the routes.
One thing I often suggest when people have questions is to first
figure out how they would do things without T4MVC. If you have no idea
how it would work, or think it may not be possible at all, then you
are probably expecting too much of T4MVC! Generally, it will not do
anything that MVC does not support.
In your case here, I'm not convinced that you could do this with plain MVC, because each of the application does not have knowledge of the other applications' routes. And generally, I don't think that MVC routing can ever general links that go outside of the current app.
I am rewriting some of sites in MVC.
I am concerned about old links out there, some I know about and some I don't.
I am looking for suggestions and code sample on how to make sure that my known and unknown links are not dead. What are your choices?
I would eventually like to phase out my old links. I hope to do this by notifying my users coming from old links about the new links.
I want to start off with something simple, as I am still learning MVC.
Another post suggested Managed Fusion URL Rewriter and Reverse Proxy.
I am the developer of the URL Rewriter you mentioned. If you would like help, please contact me as suggested in the ReadMe.txt file. What you are asking for is not out of the ordinary and can be easily accomplished using some very basic rules.
Well you brought up two important points. You want to notify your users about the new links, you biggest user your probably care about at this time is Google. You can address this concern with Google by doing a 301 Permanent Redirect. For example, this is how you would do it with the URL Rewriter syntax.
RewriteRule ^/(old-url.*)$ /new-url$1 [R=301]
The R=301 does the permanent redirect. The second your known and unknown links. For your known links you just need to map them to the correct part of your new application using the above rules. Depending on how many old url's you have you probably want to make the rewrite rule generic so one will catch many old url's.
For the unknown links you probably want to do one of two things, look over your server logs or analytics for anything important, and map those as appropriately to the correct part of your new code.
Then to make sure all the others don't totally go away you can redirect them to either your home page, internal site search, or just a generic page explaining that your site has been updated and this link is no longer in use.
Again please contact me with questions. The Managed Fusion URL Rewriter and Reverse Proxy will work perfectly with any .NET website (including MVC) on IIS 6 and any type of website on IIS 7 including PHP, Ruby, JSP, and Classic ASP.
Have a look at this article - http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
SUMMARY:Tip/Trick: Url Rewriting with
ASP.NET.
http://weblogs.asp.net/scottgu/archive/2007/12/03/asp-net-mvc-framework-part-2-url-routing.aspx
SUMMARY:Blog - ASP.NET MVC Framework
(Part 2): URL Routing.
If what you need is pretty URLs (or Search Engine Optimized), you can do it without rewriting your application. Check out URL Rewrite Module for IIS 7:
http://www.iis.net/extensions/URLRewrite/
It is Microsoft supported and supports URL rewriting and also response content rewriting (to fix your application links for example).
Daniel Vasquez Lopez.
I'm currently working on an asp.net-mvc content management system. It would be incredibly useful to be able to deploy nested applications e.g. /shop to have a separate app inside. Or even another instance of the cms.
I've found some information around talking about limiting the inheritance of the web.config but I've no idea how this maps to an MVC application. I'm hoping as its essentially the same stack it will just run. Nothing is ever that easy though.
If anyone has any experience doing this I would be really grateful. The idea of one big application to rule them all is not at all nice.
Si.
To be honest you biggest hurdle is going to be creating the routes and making sure they don't interfere with routes already in the system. After you get that working the rest is easy as pie.
The first thing you will need is an HttpModule that will be inserted in to the web.config under the . This module will be used to register and custom ViewEngines or Routes that you want to register. You do this in the same way that you do in the Global.asax but instead of putting them in the Application_Start you put them in the static constructor of the HttpModule. This is so they are only loaded once like Application_Start.
By do the above you will have created a module that is easily transportable and doesn't require the implimentor to modify their Global.asax code to get your stuff to work.
The second thing you probably want to do is create a custom configuration in the web.config to set stuff like the root path of your application. This will be prepended on to the route when you are setting it up in the HttpModule. Also you can use this to store customization information that is not appropriate for the database.
Last but not necessary is that you may want to create a custom ViewEngine that knowns and understands your folder structure. This is only necessary if you want to store the views in a different path than the default views, in order to minimize conflicts.
Check out the Grouping Controllers with ASP.NET MVC from Phil Haack.
Hope it helps,
Bruno Figueiredo
I've gone down this road before (with /blog), but found it to be doable but complicated and difficult to maintain. Instead I ended up using subdomains:
www.example.com
shop.example.com
blog.example.com
These are much easier to maintain because you can just have them work as separate websites in IIS. And, of course, you can always redirect www.example.com/shop to shop.example.com.