ASP.MVC 4 Bundles cache - asp.net-mvc

I migrated MVC3 to MVC4 and added mobile views for my website using JqueryMobile. To "improve" performance i am using Bundles to compres *.js and *.css files.
everything works fine.
After deploying (system nightly build) i saw that bundle .js and .css files are being reloaded every time without using cache.
However, if i run this page on localhost host, page load size decrease from ~1mb to 450kb.
project webconfig Debug is set to false
What could affect it. Is it posible to change directly cache-control to public?

Looks like this could well be an issue in Web Optimisations 1.1.2/1.1.3. Maybe reverting to 1.1.1 can fix the issue as suggested in the following post http://aspnetoptimization.codeplex.com/workitem/127

Related

ASP.Net MVC 5 - Deploy separate CDN site with bundled JavaScript and CSS

I was wondering whether it is possible to deploy two ASP.Net MVC sites to do the following.
Main Website: contains all the controllers and views
CDN website: contains all the JavaScript and CSS (bundles JS and CSS that is consumed by the first site)
I was expecting that in the solution you would have two website projects. I think in debug mode this would work fine because the bundle names are consistent.
However, in production where you are not running in debug mode (turned off in web.config), the file names have a query parameter that varies e.g. http://www.test-domain.com/bundles/bootstrap?v=2Fz3B0iizV2NnnamQFrx-NbYJNTFeBJ2GM05SilbtQU1 (where bootstrap is the name of the bundle).
Does anyone know how to reference the bundles in the CDN website from the Razor views in the main website?
Answer
I realised that you don't have to include the query parameter for bundle name
If your MVC 5 project work well in Release mode in your local machine, it will work on Production too.
Only few more considerations you need to take care on production are :
Make sure CORS is enabled since you have js & css resources at different site(if domain name is different)
Make sure you references at MVC5 site having hosting views & back-end logic have correct references as you have created in CDN
Firewall/hosting port is allowed on both hosting machine to communicate.
Hope this helps.
BTW querystring appended to end of URL just make sure every request is differently served by Server not as cached, nothing to impact your application.

Razor views not generating html after deploying Umbraco 7.2 in IIS 7

I am new to Umbraco, so I started creating a site to play a bit with it. While I had my site running on IIS express (either from VS or WebMatrix) everything worked fine. After deploying the site to IIS 7, the razor views of the front end are display in plain text, meaning that I actually see Razor syntax in the browser. Umbraco back office is working perfect though, except when I hit preview, in that case I get the plain Razor syntax again. I then try to deploy a simple new MVC project to IIS and the Razor engine worked just fine, so I guess is not a problem in IIS but in Umbraco configuration. Is there any configuration tweak I need to take care in Umbraco configuration to solve this problem? Thanks in advance for the help.
I also tried to deploy it in the IIS of my local development machine (the same in which it runs OK in IIS-express) which has the right framework and everything and I got the same cshtml display in the browser.
After struggling a bit more with the problem I found the issue causing this behavior. After installing the starter kit a lot of files are generated in the folder and subfolders of the solution. In order to publish the solution to generate the contents of your website the VS project needs to have all these files included as project files. I found out that some views were excluded of the project and thus not being generated when publishing. I included the missing views and double check that all important files were part of the project and problem solved.

MVC 4 bundled scripts does not reflect my changes to the script files

I have a MVC 4 application in .NET 4.0. My web hosting provider (network solutions) has virtual directories setup so I can't use the default bundling behavior (I think).
In my _Layout view I have this line:
#Scripts.Render("~/bundles/dd-d2")
In BundleConfig.cs I have
bundles.Add(new ScriptBundle("~/bundles/dd-d2").Include(
"~/Scripts/dd-d2.js"));
And everything works fine when I run in visual studio. But when i upload to my web hosting, The file is not found because it appends the virtual folder in front of the bundle path.
instead of /bundles/dd-d2?v=BlahBlah, I get /ROOT_FOLDER/bundles/dd-d2?v=BlahBlah
I fixed this issue by adding this to my line in the _Layout file
#Scripts.Render(Url.Content("~/bundles/dd-d2"))
The Url.Content helper converts the virtual path into an app absolute path and it finds my bundled script files.
Now, the problem I am having with that approach is, if I make a change to the javascript file, it is NOT reflected in the outputted bundled script file. It always has the old information in it even when I upload it to my web hosting. Is this file cached somewhere? Is there a better way of doing this? I would like to take advantage of the minification of my script files by using bundling.
if I do it this way, it does work
<script src="#Url.Content("~/Scripts/dd-d2.js")" type="text/javascript"></script>
But then my script is not minified.

Images and Script not working on deployment environment

Everything works fine on my development environment, but when from production environment it doesn't load images, and also giving error of "$" is undefined on $.document jquery function.
The site is built using ASP.NET MVC.. there is "Images" folder on root, and "Scripts" folder on root as well.
I have checked the permissions on these folders and IIS users are given read access over there.
Not sure, but its worth mentioning that I am using thinktecture as an identity server.
Please double check your jQuery reference on that page using View Source (Ctrl + U), if it's there?
OR
may be you had reference wrong path for jQuery on that page .
OR
may be you have using multiple jQuery files on page and your files is Conflict with others.
you can debug your problem using Firebug in Firefox.
Hope this will help you.... :)

ASP.NET MVC3 IIS can't get stylesheets to load

I am having trouble getting my local II7 to load stylesheets when running a default 'File/New' MVC3 website. When I run the site using Visual Studio everything works great. I created an IIS7 website pointed to the root folder of the MVC website. The site comes up, but no stylesheets load. My app pool is set for .NET 4 and Integrated mode.
The same issue was described in this topic, but the fix didn't help me (I already have the 'serve static content' setting checked).
ASP.Net MVC & Local IIS Issue Loading Stylesheets
Any direction is appreciated!
This was solved by enabling Anonymous Authentication in IIS, then right-clicking that node and choosing Edit and choosing Application Pool Identity. Everything loads correctly now. With fiddler I noticed I was getting 401 errors on the stylesheets/js files, so I knew I had a security issue.
In your layout page have the style sheet like:
<link href="#Url.Content("~/folder/style.css")" type="text/css" rel="stylesheet" />
This should help by making it relative to your applications root the #Url(Content("~/ part.
Another thing to check is that Static Content is enabled in Windows Features - this catches me out every time. In Windows 7:
Open Control Panel
Select Programs > Programs and Features > Turn Windows features on or off
Expand Internet Information Services > World Wide Web Services > Common HTTP Features
Check "Static Content"
Click OK and wait before retrying.
As #Mike said, I am almost willing to bet that the problem is that the path to the CSS file is different when you run local than when you run on the server.
Where are your CSS files located at?
For example, if your root IIS folder is c:\inetpub\wwwroot...are your CSS files under
c:\inetpub\wwwroot\somefolder\content\style.css or under
c:\inetpub\wwwroot\content\style.css
?
I had this problem too, and none of the solutions here (or anywhere else that I could find) helped.
The Solution
It turned out that my CSS files were downloaded from an external source in zip format. The files were copied and pasted from the zip file to my IIS directory using Windows Explorer. If you unzip the file first before doing the copy operation, then it won't mess up the permissions and you will be able to view them in IIS.

Resources