Today I found a weird thing in my MVC 3 app. It's quite large so I decided to use Areas. Evrything is setted proper, but for the request on SomeArea/SomeController/SomeAction I recieve 404.
On fresh MVC3 app this works as expected.
I tried to debug the app and I beieve the problem Is in Global.asax in which Method Application_Start calls AreaRegistration.RegisterAllAreas and this method should fire RegisterArea in TestAreaRegistration class. In RegisterArea is the routing rule for this area.
I fresh app, when I set a brekpoint inside RegisterArea it is reached when server strats, but in previous app, breakpoint on this place in never reached.
I havent found any differences between these two app. Normally I would take the content from previous app and put it into new, but the app is under TFS.
A few things worth checking are:
Areas are being registered. There should be a MyAreaRegistration.cs file in the area sub folder plus the list in Global.asax.cs
Does the folder containing the views match the controller name?
Is your link/ActionLink pointing to the correct place?
Does your controller have the correct namespace?
Related
My understanding (or misunderstanding): I've just started learning the mean stack and i see that a lot of tutorials (most are pretty old) and some template projects (like mean.io) using angular for routing instead of express (about 80% angular routing and 20% express). My understanding of angular routing is that it is suppose to ajax in a template into the ngView which would keep the page from reloading giving me a true single page application.
my setup: So i have express routing all request to the index file and from there i have created routes in angular for all possible request. each request is routed by angular to a jade template file (which i've seen called partials).
The issue: so i thought that angular would be ajaxing in the partial with each request (giving me the benefit of not having the whole page reload) making a true single page application, but what i've found is that because express (or any other web server for that matter) is routing all request to the index file so angular can do it's thing the index file is always reloaded with each request. because of this, I feel like the ajax routing is meaningless. After all, if the index file is always reloaded on each request which in turn reloads the angular files (and all the js and css files called in the head) then there is no real difference between angular routing and express routing coupled with jade template includes.
The question: Is this the way angular routing coupled with express is meant to be set up and suppose to function or am i doing it all wrong (or when using the mean stack, is it more of a personal choice as to which routing to use rather than a distinct advantage/dis-advantage)?
I see what is going on here: the ajax only seems to happen when following a link from within the browser. If you manually modify the url in the browser bar to test the link it will reload everything. Now i feel silly as hell.
The tutorials and example I've seen are all single page application.
Can anyone give an idea or point to a resource showing how a multiple page app can be developed with CanJS?
You should be able to create a new page in whatever app framework you are using or even just static pages, and then hookup your new control and view to any element on that new page.
You want to have a separate control for each module, so you might have separate controls even on a single page if you have, for example, a filterable dropdown list, a todo list, and a login. So, in your canjs directory for your app you will have separate sub-directories for each module which will contain your control, view/s, model/s, and observe/s and unit tests. This makes them re-usable, easier to test, and since they are modular if one part of your app breaks it won't take down all functionality. Once you get the hang of that incorporate AMD style loading of your assets with stealJS which is made by Bitovi - the CanJS creators.
https://github.com/bitovi/steal
If you want to manipulate the location.hash without actually changing pages or manaage browser history and client state you should check out can.route:
http://canjs.com/docs/can.route.html
I am trying to integrate an old ReportViewer Webform into my current MVC3 project. I would like it to be available at http://<server>/Reports/ViewReport.aspx. At first I created a folder in the root of my project titled Reports, dumped the page in there, and it worked just fine.
However, I now have an Area also called Reports, and I had to get rid of the folder in order for the default routing to work correctly.
How can I configure my routing so that the Webform URL appears to be coming from Reports even if it's physically elsewhere in my project?
The easiest way to do this is to use IIS URL Rewrite module. No changes to your application's code or routing. Just place your webpage somewhere in some non-MVC related folder that is also accessible.
http://www.iis.net/download/urlrewrite
But otherwise you could try putting your file directly in area folder as the RouteCollection.RouteExistingFiles is by default false which means that your file should be processed by the usual Asp.net web forms pipeline.
The most important thing is though that you don't put your file inside a folder with configured System.Web.HttpNotFoundHandler handler. By default Views folders have these configured so files within sub-folder tree are inaccessible from request level. Application of course can access them (that's how MVC works anyway).
I have a C#.Net web app and the pathing is different from my local box to the dev box. My local url is http://localhost:<port>/Proposal/Edit. However, on the dev server, it is http://{MydevServer}/dev/app/Proposal/Edit]. So, this causes issues with the Style Sheet and navigation links, etc. I know I can grab the ApplicationPath inside all the Controllers and set a variable whic the pathed elements can use. But that seems like too much work for this issue. Any ideas on how to solve this? Is it possible to get the ApplicaionPath in the _Layout.cshhml file? Is ther a better idea?
You can call Href("~/") in any Razor page to get the full client path to your application root.
you should be using the Url.Action and Url.Content helper methods for generating your links and src attributes. then you'll never need to worry about it.
I have an ASP.NET MVC3 Razor application getting too big to manage effectively.
To have better control over the code I implemented Areas and re-arranged the code to be in the respective areas.
Things that are used from multiple areas are left in the "normal" controller folder.
My problem arises as soon as I use an Action or ActionLink from an area.
I have to manually include a routing parameter called 'area = ""' to have the link work.
There are a lot of links to be changed, so I tried to have the controller selection fallback to the "root" controllers to find the needed controller.
I had no luck so far.
What do I have to do to enable MVC3 to search through the area controllers and continue to search in the root controllers folder if the controller is not found?
Thanks
Andreas
You can do this by setting up your routes appropriately.
Each area has it's own route supplier, and then there are the routes in the global.ascx. The routes act sort of like a case statement, where it tries to find the routes in the areas first, and if it doesn't find a matching route, it then falls through to the global.ascx routes.
So, in your new areas, setup a catchall route, and in the global.ascx setup a catchall route and you should be ok.
You can use Haack's route debugger to see what is happening with your routes.