GetOverriddenBrowser() for ASP.NET MVC 3 - asp.net-mvc-3

ASP.NET MVC 4 has some nice mobile features which are replacing my mutant mobile view engines, but until it's production ready, I'd like to implement the browser override feature for ASP.NET MVC 3.
SetOverriddenBrowser() seems to set a .ASPXBrowserOverride cookie with an overriding User Agent that returns an HttpBrowserCapabilitiesBase object via HttpContext.GetOverriddenBRowser().
What would be the simplest way of implementing this feature for MVC 3 to make use of the mobile detection library, including 51Degrees.mobi?

There is a blog post on the 51Degrees.mobi site that you might find useful. Check it out here. It covers the implementation of 51Degrees with MVC 4.

Related

Mixing ASP.NET Webforms with Friendly URLs with new ASP.NET MVC stuff

I have a number of "old-style" ASP.NET 4.x Webforms applications. For future development, we're thinking about switching to ASP.NET MVC 5, and we plan to basically add new features as MVC code to our existing apps.
Now I found a number of interesting articles on how to mix Webforms and ASP.NET MVC, and one of the topics usually is around routing. Typically, the consensus is to define a "route ignore" setting for all *.aspx requests - those get handled by the "old" Webforms runtime.
This is all nice and fine - but we're already using the Webforms "friendly URL" feature - so our requests are like
http://myserver.com/myapp/customer/42
http://myserver.com/myapp/product/edit/57
and we don't have any ".aspx" in our query string anymore.
So given this setup - Webforms 4.5.x with Friendly URL's (without the ".aspx" indicator) - how do I make sure that my new MVC routes don't collide with existing Webforms friendly URLs ?
Do I need to stick all the MVC stuff into an "area" (or several) and just define those URLs as the MVC routes? E.g.
http://myserver.com/myapp/mvc/newhotness/404
***
or are there other, more compelling approaches to this?

A good substitute for ASMX web service methods, but not a general handler

The best thing I like about ASP.NET MVC, is that you can directly call a server method (called action), from the client. This is so convenient, and so straightforward, that I really like to implement such a model in ASP.NET WebForms too.
However, in ASP.NET WebForms, to call a server method from the client, you should either use Page Methods, or Web Services, both of which use SOAP as their communication protocol (though JSON can also be used).
There is also another substitution, which is using Generic Handlers. The problem with them however is that, a separate Generic Handler should be written for each server method. In other words, each Generic Handler works like a simple method.
Is there anyway else to imitate MVC model in ASP.NET WebForms?
Please note that I can't change to MVC platform right now, cause the project at our hand is a big project and we don't have required resources and time to change our platform. What we seek, is a simple MVC model implementation for our AJAX calls. A problem that we have with Web Services, is the known problem of SoapException, and we're not interested in creating custom SoapExctensions.
You can mix ASP.NET MVC and ASP.NET Webforms in the same project. You'll just need to add the correct MVC parts to your current Webforms project and have the best of both worlds.
http://www.aspnetmvcninja.com/general/mixing-asp-net-mvc-and-webforms has a good walkthrough of all the steps you'll need to take to get it working.
You can splice your asp.net webforms app with something like Nancy perhaps?
I've had great success with Nancy and Knockout after I abandoned the horrible Ajax Control Toolkit.
(Apologies if I have misunderstood your question - I read it twice)

Preventing hotlinking in IIS7 and ASP.NET MVC3

What is the most straightforward way to prevent hotlinking in ASP.NET MVC 3 and IIS7?
Thanks.
Remember, ASP.Net MVC 3 is still ASP.Net underneath. Which means you can use standard methods. For example the LeechGuard Module provided by Microsoft.

Is Donut caching available in ASP.NET MVC 3

ASP.NET MVC 3 (final) was released today. When this version was in its infancy I remember reading on codeplex that donut caching was being considered. Does anyone know if this made it into V3? I cannot seem to find any information so I can only (sadly) assume that it didn't happen.
Yes, it is. Scott Gu blogged about it:
In addition to supporting full page
output caching, ASP.NET MVC 3 also
supports partial-page caching – which
allows you to cache a region of output
and re-use it across multiple requests
or controllers. The [OutputCache]
behavior for partial-page caching was
updated with RC2 so that sub-content
cached entries are varied based on
input parameters as opposed to the URL
structure of the top-level request –
which makes caching scenarios both
easier and more powerful than the
behavior in the previous RC.
UPDATE:
Out of the box only donut hole caching is supported in ASP.NET MVC 3. This allows you to cache a small portion of the page by using the [OutputCache] attribute on a child action. Donut caching which allows for excluding portions of a page that has been cached is not supported. Response.WriteSubstitution doesn't work since ASP.NET MVC 2. Here is a good article which explains the different caching options available in ASP.NET MVC 3.
UPDATE 2:
Here's a great article which illustrates how donut caching could be enabled in ASP.NET MVC 3.
Here's a slightly more detailed example from Scott, using Razor syntax.
Donut Caching (yes, the real thing) is available as part of my 'speed-lib' for MVC: Moth. Works in both ASP.NET MVC 2 and MVC 3.
Docs are at the wiki, and examples are in the Mvc3.Demo folder
I found a NuGet package MvcDonutCaching mentioned by Denis Huvelle which solves the problem for 3 & 4 - but I haven't tested it.

Is ASP.NET MVC flexible?

Can it easily be combined with jQuery, (ASP.NET) Ajax, ASP.NET webforms, other frameworks.
What about pulling dynamic code from ASP.NET MVC into for example classic ASP?
Does the MVC model mean that it is easy to customize code?
Background:
I have some experience that it can lead to problems to integrate frameworks relying on JavaScript with each other?
We have a classic ASP where we write new stuff in ASP.NET, and include .aspx code in the ASP files.
I am looking for some OS frameworks for stuff we need, and i think MVC based ones should be easier to adopt (KIGG)
ASP.NET MVC ships with jQuery as the default javascript framework, so no worries there. There aren't really any ties in the framework itself to jQuery so you could also switch it out with a framework of your choice. MVC comes with it's own AJAX implementation that builds on the base ASP.NET Ajax implementation (at least in javascript), so there is AJAX support but I think you'll find that it's different -- no UpdatePanels, for instance -- but you're able to do similar things.
You can mix WebForms with MVC, but you'll need to set up IgnoreRoutes for those URLs so they don't get processed. I confess that I haven't found a need to do this yet, but then I don't use third-party controls. That might be an area where, at least for now, you still need some WebForms. I've never used classic ASP and likely won't so I can't help you there.
You can use any Javascript framework with MVC, they have included Jquery as the default but any can work with it.
As far as flexibility, we have deployed a working site with ASP.NET webforms, MVC and .NET 1.1 libraries, so yes it is flexible.
In our experience ASP.NET MVC is the best thing MS have done for web development, especially if you like to control closely your html output and use web standards in your layout and design. We have used it for 6 Months and we are NEVER going back to web forms.
Have fun!

Resources