ASP.NET MVC3 IIS can't get stylesheets to load - asp.net-mvc

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.

Related

I can't display/browser my images in Virtual Directory in IIS

From a remote server with Microsoft Server 2016 where I am admin, I publish my ASP.NET Core MVC web app in Visual Studio 2019 via IIS Server 2016 as a Website called "demo".
dotnet-hosting-3.0.2-win, dot-net-3.0.102 sdk bundler and urlrewrite2 are installed.
The project is just the simplest "Hello" demo, it works.
Then in I add a Virtual Directory to my website in order to display images from a shared folder.
When I create this Directory, I tried both methods:
- "Connect as" / my user log. "Test settings" gives an OK icon.
- "Application user" + Edit Permissions / Security / Edit / Add / IUSR
Once my Directory added, I can see the content of it in Content View panel, 2 images.
I also tried to add the Directory to wwwroot of my website.
I precise that in Features View panel, Directory Browsing is enabled.
I also tried to access my images via code.
This is what I get:
I am pretty new with deployment, still I have read a lot of documentation, but I can't make it work. What did I miss? Is there something to do with a webconfig in IIS?
I am not expert but as per my little understanding of IIS and ASP.NET MVC, please try following.
Click on your "demo" site in iis manager and on the right side, under "actions" pane click browse. And then navigate to your images folder from browser.
Also, you can only see individual files under this directory and not a list of files.
You can access individual file using the spcefic URL, for example http://localhost/images/image1.jpg
If you hit "http://localhost/images" this URL, IIS will try to find a controller or action method by this name.
Lost my problem thanks to this link:
Virtual directory inside of ASP.NET Core app in IIS
The big picture I get is Net Core is just not designed by default for IIS/Virtual Directory, but you can get your stuff by modifying the applicationHost.config of IIS manager.
Supposing your Virtual Directory is called "bilder" in the website "democore", you would write this at the end of your applicationHost.config:
Hope it will help.

visual studio not updating html / javascript to server / browser

This is an MVC 4 app using the Hot Towel SPA template. Whenever I change anything in the HTML and/or javascript the only way I can get the new code to display is to clear the browser cache. F5, cntrl-F5, shift-F5, nothing works.
I'm not normally a web dev and just learning this. I've done regular MVC before and not had this issue, maybe it has to do with where the HTML and javascript is in my project (i.e. in the /App folder) ?. I'm going nuts trying to figure this out.
I can completely delete an HTML file and run the app and it still runs as it did. Clear cache and run and I then get the update.
It's running using IIS express using Firefox, Chrome, IE...
Thanks..
In Opera and Chrome (and possibly others), you can disable caching while in 'development mode'.
While in DevTools, the 2nd option in the Settings menu is
Disable cache (while DevTools is open)
Go to your web.config file and make a change in it.Its not matter what change you make.For example type a character and then delete it and build the project and run it again.I hope it works.
I also experienced this issue and turns out it was related to caching.
If using Chrome DevTools, you can simply disable cache by navigating to the Network Tab and ticking Disable Cache
This will only disable the cache when Dev Tools is open.
ctrl+shift+F5 will do the trick! Seems like browser cache is part of the problem :)
in my case iis express not updated site, but site , created by iis Manager worked correctly?
possible solution for this problem is
set "use this 64 bit version of iis express for web sites and projects" option at visual studio
it located at options->Projects and Solutions->Web projects
I found that I had the .js file open in the Chrome Developer Tools -> Sources View.
When I closed the file there and refreshed the page the new .js file showed up as expected.
The browsers cache by default. You can turn off caching in your browser to get the changed files.
I had an issue with moved .ts & .html files on the server and had to:
stop debugging
clear the whole output/dist folder inside my ClientApp
start debugging again
Ctrl-F5 to force the cache to refresh on the browser
Simply disabling the browser's cache, or forcing the .net app to recompile, or even running ng serve had no effect.
None of the above listed methods works consistently and if one considers that different browsers are used in the task pane depending on Windows version/build used then you may have to clear the cache of a different browser in each case.
However, it seems that the real issue is not so much browser caching as it is VS deciding which files to deploy to the local IIS Express server used for testing/development. In many cases, when pressing the "Start" button, modified html and/or js files won't make it to the local deployment even if you also modify the web.config file.
The way I made this work consistently is I selected the web application project (in Solution Explorer), opened properties, clicked the "Package/Publish Web" tab and then under "Items to deploy" I selected "All files in this project".
Works fine for me!
If you just want to test locally You can try
A) Create Virtual Directory
Follow below path: Project / Properties / Web
Find Servers section
Click on Create Virtual directory
B) Follow below path: Project / Properties / Web
Find Servers section
Click on Drop down and change the selected value between Express and Local
Then Create Virtual directory
Following are some of the options that we can use to solve the problem.
ctrl + shift + r (This will do a hard refresh of your current tab)
ctrl + F5 (This will force the cache to refresh on the browser)
Stop debugging and Change the web.config file and run again
Stop debugging and clean the project, Rebuild it and run the project
In case disabling the cache and editing the web.config file does not work.
Simply close the solution and reopen it and try it. Strange, but it worked for me.

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.... :)

images, css and js files are not being loaded in my application

This one is killing me, neither of those files are loaded in my application: images, css, js, everything was working fine before re-installing my PC, so I guess is configuration issue with IIS, since i haven't touch code and works well in a PC of a co-worker.
When seeing the HTML in firebug I see this
Reload the page to get source for: http://localhost/Common/Scripts/jquery-1.4.3.min.js
this is the code
<script src="#Url.Content("~/Scripts/jquery-1.4.3.min.js")" type="text/javascript"></script>
I am running Windows 7 and IIS 7.5, it's an Asp.Net MVC 3 Application.
I have tried the following
uninstall and re-install IIS
added read permission on file system to IUSR and IIS_USRS
In the application in IIS, in feature anonymous authentication, I selected "application pool indentity".
Nothing happens, maybe someone has another idea of what's happening.
Or at least point me a direction to better understand the reason of the problem and I will update the question with the feedback.
help will be appreciated... and rewarded :)
thanks
I found the problem.
I didn't mark Static Content in features for IIS.
In Windows Features go to, Internet Information Services > World Wide Web Services > Common HTTP Features > Static Content
Under Application Development Features I selected Asp.Net it selected automatically everything else, I wonder why It didn't select this option too.
Hope it helps to someone else.

How to deploy Umbraco 5 website

I hope I'm asking this question in the right place. I also asked on umbraco forum, but did not get any response yet.
I'm having problem with deploying my Umbraco 5 website to external hosting.
On local machine, I used Umbraco 5 template for VS2010, which works fine (although it's quite slow).
When I publish to live server I get 500 error.
So far, i've tried installing fresh copy of umbraco on hosting (works fine).
I copied config files in hive provider folder (in App_Data), to point umbraco to my hosting database. That does not throw any exceptions yet. Problem starts when I copy views and partial views over - umbraco then finds the template defined in database and tries to load that.
It's worth mentioning that I also copied my project.dll file into bin directory on the server - the reason for that is because I have added new controller which inherits from surfacecontroller (in /Controllers folder).
Please let me know if I'm doing something wrong.
Cheers
Sebastian
It is not any different than deploying a MVC3 website.
There are quite a few questions with exactly that signature here on so.
Visual studio even has a few tools to help you in the process.
The publish function is found right clicking the project in the solution explorer.
If you use the template for developing, you have a working umbraco solution locally right?
If that is the case, it is easier to just deploy / publish the entire site intead of copying bits into another umbraco solution.
Publish tool
When using that tool, remember that umbraco has quite a few config files etc. and they all need to be included. So it is probably the easiest to just export all files in the folders, by changing "which files to include" setting in publish tool. That will unfortunately include all your .cs files too, but later they can be filtered out of the publish process.
First make it work, then make it awesome :)
The same goes for compilation mode, i have found that release mode sometimes breaks things, so for now just keep it in debug mode.
Then later when you have it working, you can change to release mode for a small performance gain.
Stuff to remember
include all necessary files
change connectionstrings
copy databases
custom errors, you don't want your visitors to see YSOD's with your internal debugging info.
disable tracing and debugging!
After reading this, you should go on and look for other more elaborative resources too.
"umbraco then finds the template defined in database and tries to load that" is key point to me
whatever the version you follow the templates and doc types are the backbones of umbraco ( from you website I know that you are aware with above more then me.. but repeating.) I mean you have created new website but there are no relative Templates and Doctype yet you try to use them in views and subviews and that caused the problem.
To do that please create tempalte and doctype same as is in you staging site and this problem will be solved.
Even better kick-start you development with new site only and make replica of that after defining doc-type and templates to your staging.
I hope i can explain my point.
Thanks,
Jigar
I've had problems in the past deploying Umbraco 5 projects. When you deploy an Umbraco 5 website to a new server and before you switch the website on in IIS, navigate to \App_Data\ClientDependency and delete any XML files that are there. Next, navigate to \App_Data\Umbraco\HiveConfig and delete the ConfigurationCache-*.bin files.
Once you've done that, recycle your Application Pool and start your website.

Resources