Mobile devices wont get View.Mobile.cshtml views after visiting page with desktop












0















I created a asp.net mvc app with a Index.cshtml and a Index.Mobile.cshtml. The views are using the same controller and action. In development I get the mobile view on my phone and with desktop the desktop view. Everything works as expected.



After deploying the application to the production server everything works as expected on a smartphone, until I navigate from a desktop browser to the page. After I navigated from a desktop browser to the page I won't get the mobile view anymore on a mobile device.



I disabled and enabled cache settings but get either way i have this strange behavior. Am i missing something?



edited:



I got the following theme structure:



/Themes/DefaultTheme/Views/Cart/Index.Mobile.cshtml
/Themes/OceanasTheme/Views/Cart/Index.cshtml



In my custom razor view engine I modified the ViewLocationFormats, simplified:



var customViewLocationFormats = new List<string>();
customViewLocationFormats.Add("~/Themes/DefaultTheme/Views/{1}/{0}.cshtml");
customViewLocationFormats.Add("~/Themes/OceanasTheme/Views/{1}/{0}.cshtml");

//override default view location
ViewLocationFormats = customViewLocationFormats.ToArray();


When I copy the Index.Mobile.cshtml to the OceanasTheme folder the same problem appears, except I get the Mobile.сshtml from the OceanasTheme each time after I visited with desktop. (the desktop gets the Index.cshtml from the OceanasTheme).



Updated to MVC 5.2.7 and removed Microsoft.AspNet.Mvc.FixedDisplayModes package. But it still doesn't work.










share|improve this question

























  • pls share your code for more details

    – Yash Soni
    Nov 24 '18 at 6:31











  • How did you turn-off the caching? Are you using [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] ?

    – Mavi Domates
    Dec 14 '18 at 12:21
















0















I created a asp.net mvc app with a Index.cshtml and a Index.Mobile.cshtml. The views are using the same controller and action. In development I get the mobile view on my phone and with desktop the desktop view. Everything works as expected.



After deploying the application to the production server everything works as expected on a smartphone, until I navigate from a desktop browser to the page. After I navigated from a desktop browser to the page I won't get the mobile view anymore on a mobile device.



I disabled and enabled cache settings but get either way i have this strange behavior. Am i missing something?



edited:



I got the following theme structure:



/Themes/DefaultTheme/Views/Cart/Index.Mobile.cshtml
/Themes/OceanasTheme/Views/Cart/Index.cshtml



In my custom razor view engine I modified the ViewLocationFormats, simplified:



var customViewLocationFormats = new List<string>();
customViewLocationFormats.Add("~/Themes/DefaultTheme/Views/{1}/{0}.cshtml");
customViewLocationFormats.Add("~/Themes/OceanasTheme/Views/{1}/{0}.cshtml");

//override default view location
ViewLocationFormats = customViewLocationFormats.ToArray();


When I copy the Index.Mobile.cshtml to the OceanasTheme folder the same problem appears, except I get the Mobile.сshtml from the OceanasTheme each time after I visited with desktop. (the desktop gets the Index.cshtml from the OceanasTheme).



Updated to MVC 5.2.7 and removed Microsoft.AspNet.Mvc.FixedDisplayModes package. But it still doesn't work.










share|improve this question

























  • pls share your code for more details

    – Yash Soni
    Nov 24 '18 at 6:31











  • How did you turn-off the caching? Are you using [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] ?

    – Mavi Domates
    Dec 14 '18 at 12:21














0












0








0


1






I created a asp.net mvc app with a Index.cshtml and a Index.Mobile.cshtml. The views are using the same controller and action. In development I get the mobile view on my phone and with desktop the desktop view. Everything works as expected.



After deploying the application to the production server everything works as expected on a smartphone, until I navigate from a desktop browser to the page. After I navigated from a desktop browser to the page I won't get the mobile view anymore on a mobile device.



I disabled and enabled cache settings but get either way i have this strange behavior. Am i missing something?



edited:



I got the following theme structure:



/Themes/DefaultTheme/Views/Cart/Index.Mobile.cshtml
/Themes/OceanasTheme/Views/Cart/Index.cshtml



In my custom razor view engine I modified the ViewLocationFormats, simplified:



var customViewLocationFormats = new List<string>();
customViewLocationFormats.Add("~/Themes/DefaultTheme/Views/{1}/{0}.cshtml");
customViewLocationFormats.Add("~/Themes/OceanasTheme/Views/{1}/{0}.cshtml");

//override default view location
ViewLocationFormats = customViewLocationFormats.ToArray();


When I copy the Index.Mobile.cshtml to the OceanasTheme folder the same problem appears, except I get the Mobile.сshtml from the OceanasTheme each time after I visited with desktop. (the desktop gets the Index.cshtml from the OceanasTheme).



Updated to MVC 5.2.7 and removed Microsoft.AspNet.Mvc.FixedDisplayModes package. But it still doesn't work.










share|improve this question
















I created a asp.net mvc app with a Index.cshtml and a Index.Mobile.cshtml. The views are using the same controller and action. In development I get the mobile view on my phone and with desktop the desktop view. Everything works as expected.



After deploying the application to the production server everything works as expected on a smartphone, until I navigate from a desktop browser to the page. After I navigated from a desktop browser to the page I won't get the mobile view anymore on a mobile device.



I disabled and enabled cache settings but get either way i have this strange behavior. Am i missing something?



edited:



I got the following theme structure:



/Themes/DefaultTheme/Views/Cart/Index.Mobile.cshtml
/Themes/OceanasTheme/Views/Cart/Index.cshtml



In my custom razor view engine I modified the ViewLocationFormats, simplified:



var customViewLocationFormats = new List<string>();
customViewLocationFormats.Add("~/Themes/DefaultTheme/Views/{1}/{0}.cshtml");
customViewLocationFormats.Add("~/Themes/OceanasTheme/Views/{1}/{0}.cshtml");

//override default view location
ViewLocationFormats = customViewLocationFormats.ToArray();


When I copy the Index.Mobile.cshtml to the OceanasTheme folder the same problem appears, except I get the Mobile.сshtml from the OceanasTheme each time after I visited with desktop. (the desktop gets the Index.cshtml from the OceanasTheme).



Updated to MVC 5.2.7 and removed Microsoft.AspNet.Mvc.FixedDisplayModes package. But it still doesn't work.







asp.net asp.net-mvc-4






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 10 '18 at 12:37







Joost

















asked Nov 23 '18 at 21:38









JoostJoost

4710




4710













  • pls share your code for more details

    – Yash Soni
    Nov 24 '18 at 6:31











  • How did you turn-off the caching? Are you using [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] ?

    – Mavi Domates
    Dec 14 '18 at 12:21



















  • pls share your code for more details

    – Yash Soni
    Nov 24 '18 at 6:31











  • How did you turn-off the caching? Are you using [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] ?

    – Mavi Domates
    Dec 14 '18 at 12:21

















pls share your code for more details

– Yash Soni
Nov 24 '18 at 6:31





pls share your code for more details

– Yash Soni
Nov 24 '18 at 6:31













How did you turn-off the caching? Are you using [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] ?

– Mavi Domates
Dec 14 '18 at 12:21





How did you turn-off the caching? Are you using [OutputCache(Location = OutputCacheLocation.None, NoStore = true)] ?

– Mavi Domates
Dec 14 '18 at 12:21












1 Answer
1






active

oldest

votes


















1














RazorViewEngine is caching views with DefaultViewLocationCache. The .Mobile view location is stored in cache after first request with mobile. When requesting with a desktop browser the desktop variant is not found in the cache, so RazorViewEngine is gonna try to find the view on the disk. It will find the view in the different folder, and will store it in cache, But it also checks if the mobile exists in that folder. Because the .Mobile is not in this folder it will overwrite the cache with an empty path.



I fixed this issue by creating a custom implementation of IViewLocationCache.






share|improve this answer
























  • Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

    – Mavi Domates
    Dec 17 '18 at 13:25











  • See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

    – Joost
    Dec 20 '18 at 10:14













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453191%2fmobile-devices-wont-get-view-mobile-cshtml-views-after-visiting-page-with-deskto%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














RazorViewEngine is caching views with DefaultViewLocationCache. The .Mobile view location is stored in cache after first request with mobile. When requesting with a desktop browser the desktop variant is not found in the cache, so RazorViewEngine is gonna try to find the view on the disk. It will find the view in the different folder, and will store it in cache, But it also checks if the mobile exists in that folder. Because the .Mobile is not in this folder it will overwrite the cache with an empty path.



I fixed this issue by creating a custom implementation of IViewLocationCache.






share|improve this answer
























  • Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

    – Mavi Domates
    Dec 17 '18 at 13:25











  • See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

    – Joost
    Dec 20 '18 at 10:14


















1














RazorViewEngine is caching views with DefaultViewLocationCache. The .Mobile view location is stored in cache after first request with mobile. When requesting with a desktop browser the desktop variant is not found in the cache, so RazorViewEngine is gonna try to find the view on the disk. It will find the view in the different folder, and will store it in cache, But it also checks if the mobile exists in that folder. Because the .Mobile is not in this folder it will overwrite the cache with an empty path.



I fixed this issue by creating a custom implementation of IViewLocationCache.






share|improve this answer
























  • Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

    – Mavi Domates
    Dec 17 '18 at 13:25











  • See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

    – Joost
    Dec 20 '18 at 10:14
















1












1








1







RazorViewEngine is caching views with DefaultViewLocationCache. The .Mobile view location is stored in cache after first request with mobile. When requesting with a desktop browser the desktop variant is not found in the cache, so RazorViewEngine is gonna try to find the view on the disk. It will find the view in the different folder, and will store it in cache, But it also checks if the mobile exists in that folder. Because the .Mobile is not in this folder it will overwrite the cache with an empty path.



I fixed this issue by creating a custom implementation of IViewLocationCache.






share|improve this answer













RazorViewEngine is caching views with DefaultViewLocationCache. The .Mobile view location is stored in cache after first request with mobile. When requesting with a desktop browser the desktop variant is not found in the cache, so RazorViewEngine is gonna try to find the view on the disk. It will find the view in the different folder, and will store it in cache, But it also checks if the mobile exists in that folder. Because the .Mobile is not in this folder it will overwrite the cache with an empty path.



I fixed this issue by creating a custom implementation of IViewLocationCache.







share|improve this answer












share|improve this answer



share|improve this answer










answered Dec 15 '18 at 16:25









JoostJoost

4710




4710













  • Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

    – Mavi Domates
    Dec 17 '18 at 13:25











  • See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

    – Joost
    Dec 20 '18 at 10:14





















  • Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

    – Mavi Domates
    Dec 17 '18 at 13:25











  • See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

    – Joost
    Dec 20 '18 at 10:14



















Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

– Mavi Domates
Dec 17 '18 at 13:25





Can you share a bit of your code which uses your implementation of this please? It would be greatly helpful to anyone who's running into the same issue.

– Mavi Domates
Dec 17 '18 at 13:25













See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

– Joost
Dec 20 '18 at 10:14







See for reference: github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Mvc/… I just created a additional check before setting the cache in the InsertViewLocation method.

– Joost
Dec 20 '18 at 10:14






















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453191%2fmobile-devices-wont-get-view-mobile-cshtml-views-after-visiting-page-with-deskto%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin