Optimization Bundles and Umbraco 4 - asp.net-mvc

I've recently setup a hybrid Umbraco 4.8 webforms + mvc application (see aaron powell's post on this: http://www.aaron-powell.com/umbraco/using-mvc-in-umbraco-4)
I have everything working great. I even configured ninject and I'm using MVC4 optimization bundles. The problem is that when I try to enable optimizations the dynamic routes are getting picked up by the umbraco url rewriter and I can't render CSS or JS files in the release configuration.
This renders fine (since it's a static route):
http://myserverUrl/Scripts/jQuery/jquery.js
This doesn't:http://myserverUrl/js/combined?v=J_D8qmUMMTWvtIuuef2sskA8d2JCiGB9kNZMq_nNKpw1

Umbraco handles all the request, that aren't to a static file, so you need to configure Umbraco to skip those pathes
In web.config put "~/js" as a reserved url, just as you have done to the route you made.
<add key="umbracoReservedPaths" value="~/umbraco,~/install/,~/js" />

Related

Mapping .css and image files through asp.net even with Integrated Pipeline and asp.net MVC 3

I've got some complex routes setup in my asp.net mvc 3 project, unit tested and working on development. For the most part they're working with IIS7 and Integrated Pipeline and having mapAllRequests=true.
But I'm also doing some funky routing with 'some' of the requests for images and css. I'm not sure if it's the logic or if it's IIS taking over when it see's css or img files. I want IIS to take over if it finds the static file otherwise send it to the mvc routing, is this possible?
Not with app pool in integrated mode - all requests are passed to the application. By default, MVC does not route requests for static files (it maps url-paths to them just like non-mvc asp.net, which is the behavior that you want).
You can change that behavior (routes.RouteExistingFiles = true) if you want to do something special within responses to static files. More info about this property:
ASP.NET MVC RouteExistingFiles question
Considerations when turning on RouteExistingFiles
http://msdn.microsoft.com/en-us/library/ie/cc668201.aspx
I hope this helps.

Hosting an MVC and a webforms site on the same IIS7 instance - web.config inheritance

We have a website that was written in classic ASP, then I started to extend it using web forms. These extensions exist in a subfolder of the main folder. Now we've decided we'd prefer to use MVC3. Also, as we'd like to convert all our site to MVC3 over time, we are hosting the MVC code in the application root. I've found some other questions where people have a similar issue to mine, but no solution. The issue is simply that my web forms app can't seem to be stopped from inheriting the web.config settings from the root folder, and as a result, it won't run, it either complains about missing dlls, or complains about running the wrong version of .NET, or complains I need to remove some settings ( which I try and can never get to work right ). The app in the subfolder is also hosting a webservice that is called by our application, and it also runs HTTP handlers to protect our imaging content, so it's got a bit of stuff in it. Do I need to run my MVC site in a subfolder ? Is there any way to have MVC in the folder above a web forms app ? I'd prefer to set things up so they share session data, but that's looking likely to be impossible at this stage...
So to be clear the folder structure is:
<root>
contains asp site and MVC site.
<subfolder>
contains webforms application
</subfolder>
</root>
and my issue is getting the subfolder to run, preferably in the same session as the MVC app.
There is no reason you can't run regular .aspx files on an MVC site. You are correct though, web.config settings are inherited from the parent (chain), but you just add a new web.config in your directory with relevant settings.
What you will have to do is play with the routes, because by default MVC will route all requests into your controller classes. But if you google around its fairly simple to add an exception to the routing.
If you post some of the specific errors we can probably help further.
Oh and do you mean Classic ASP? i.e. not Classic ASP.NET? Because you'll have fun sharing session data between ASP & ASP.NET.

asp.net MVC 3 no default page

Has anyone tried to deploy an asp.net mvc 3 website that uses the razor templates? The project does not create a default page and not sure if this changes in some way?
I have several projects in the pipeline that work on both IIS 7 and 6 (test servers) without any issues with a missing default.aspx page. I don't have any production code in effect but so far it's not an issue.
I would say the issue with a missing default.aspx page would rely on the server not using the <modules runAllManagedModulesForAllRequests="true" /> in the web.config. Otherwise a default.aspx page isn't necessary for handling. As long as IIS uses the mvc module to handle requests.

ASP.NET MVC Application in Sharepoint 2007 virtual directory

I have MOSS 2007 installed at lets say http://localhost:4999/ and I want to have my custom ASP.NET MVC (1.0) application at http://localhost:4999/mvcapp/ - logic dictates that, in IIS, i should create a new application virtual directory under my MOSS site and point it at my custom MVC app.
I've done this and it works for executing my controllers etc, however, none of my /Content content is being returned! All referenced images, javascript and css aren't retrieved.
If I put this app into it's own site, or a virtual application within a non-sharepoint site, this works fine and pulls down the images, js and css as normal.
Note - I'm creating a new application in IIS, not just a virtual directory and I have no requirement for integrating with sharepoint, I just want it to have the same domain and port number.
Any ideas?
Cheers
Tony
** EDIT **
To clarify - the URL's that are being generated aren't the issue - they are correct and are being generated in the same way as they would be if this wasn't hosted under sharepoint. IE: /mvcapp/Content/Scripts/jquery.js etc.
** EDIT 2 **
More clarification - the MVC app has it's own web.config file - but it appears that when using a virtual directory withn a sharepoint site, many of the handler mappings still get pushed up to the child site (Note: This is a virtual directory configured as a seperate application not just a virtual directory).
Whilst I don't want or need SharePoint integration, I need my MVC app to come from the same domain and port to overcome some cross domain issues (a lot of MVC content is iframed into sharepoint in various ways). So sharepoint would be at http://site and my app at http://site/mvc
I would keep them on separate web sites (MVC and SharePoint that is). You could create a new website entirely for your MVC app, and then through IIS, right click your MVC web site, edit bindings, and redirect the traffic from your MVC website to URL you want.
I set up a couple of WebForms apps to run in much the same way you say that you want: a separate virtual application with its own web.config, etc. I had to tweak the web.config to make it work, though. My app uses things like session state and view state, but I reckon those aren't applicable to your MVC app. As I look at my web.confing, I think this section might be applicable for what you're trying to do:
<location>
<system.web>
<xhtmlConformance mode="Legacy" />
<trust level="Full" />
<httpModules>
<remove name="PublishingHttpModule" />
</httpModules>
</system.web>
</location>
Hope that helps. I also have an <authorization> section in there, but it wasn't necessary to make the app work.
Look at the following:
Configuring Specific Files and Subdirectories (MSDN)
Disabling Configuration Inheritance For ASP.NET Child Applications (Blog)
HTH

What's the difference between ASP.Net MVC Routing and the new ASP.Net DynamicData Site routing?

I've only started playing with both ASP.Net MVC and the new-to-VS2008 Dynamic Data Website Templates. I note that they both use routing in their URL handling, and I'm given to understand that because of routing, ASP.Net MVC won't work under IIS6. However my DynamicData site works just fine on IIS6.
I've had to temporarily abandon my exploration of ASP.Net MVC for an upcoming project due to the IIS7 requirement, and I'm wondering what the essential difference between the two is under the hood, i.e. what makes DynamicData sites work on IIS6 and MVC not?
ASP.NET MVC does indeed work under IIS6 (and IIS5 for that matter) as long as you enable wildcard mappings to ASP.NET. I have deployed MVC applications to production using IIS6, so I can guarantree that it's possible.
The key difference is that all URLs in DynamicData end in a file with an ASPX extension so, regardless of physical existance, the ASP.NET runtime is invoked (because ASPX is associated with ASP.NET), whereas most ASP.NET MVC requests to not have an extension (or have an MVC extension, which is not mapped by default) and thus IIS configuration is required before it will work.
IIS7 works automatically because IIS7 itself is managed and thus there is no separation between IIS/ASP.NET.
They all work on IIS6 out-of-the-box, without modifying IIS6. You just have to use some extension that is mapped to asp.net isapi, like .aspx, .ashx or similar.
Also, ASP.NET MVC works on IIS6 without problems! I run it moslty on IIS6, with .html extension mapped to asp.net isapi!
Some shared hosting providers are willing to make changes to IIS6 in order to support extension-less urls. If they don't want to do that, you can ask them to map .html to asp.net, urls are nice with that and seo friendly. Just to mention; google won't mind if you have .aspx or .html, it's the same like without extension.
ASP.Net MVC and Dynamic Data use the same routing engine contained in System.Web.Routing, so they both work under IIS6. The issue is with mapping requests to ASP.Net (as described by #Richard Szalay). MVC will work fine under IIS6 if a wildcard mapping is used, if the .mvc extension is mapped to ASP.Net, or if another file extension already mapped to ASP.Net (.aspx, .ashx, .axd, etc.) is used in your MVC routes.

Resources