ASP.Net MVC4 Mobile-Aware OutputCache -


i'm working on upgrading application mvc3 mvc4 , noticed assumed (hoped?) "just work".

code:

[outputcache(duration = 600, varybyparam = "none")] public actionresult index() {    return view(); } 

this textbook caching example asp.net. whenever browser hits page, checks cache see if exists, generates view if not, , sends cached results.

this works great; however, playing around mobile view functionality of mvc4, noticed above code not check see if request mobile device. if hit route on desktop, desktop view displayed on phone until cache invalidated. reverse true (if first hit page phone, desktop see mobile view instead).

is there parameter use make work hoped or looking @ building customer outputcacheprovider?

after bit more digging, found solution issue.

updated controller action

[outputcache(duration = 600, varybycustom = "ismobile")] public actionresult index() {    return view(); } 

override getvarybycustomstring in global.asax

public override string getvarybycustomstring(httpcontext context, string custom) {     if (custom.tolowerinvariant() == "ismobile" && context.request.browser.ismobiledevice)     {         return "mobile";     }     return base.getvarybycustomstring(context, custom); } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -