Broken Images on IIS7

I have an ASP.NET MVC site and it works fine when I run it locally. As soon as I deploy this site in IIS 7, all links to resources are broken (i.e. script files, images, css files). Could this be a route issue or would it be an IIS setup?

Here are my routes:

public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("elmah.axd"); routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( "Search", "Basic/Page/{page}", new { controller = "Search", action = "Basic" } ); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = MVC.Welcome.Name, action = MVC.Welcome.Actions.Index, id = "" } // Parameter defaults ); } 

EDIT:

I reference all content using the T4MVC template. The pattern is correct if it sets paths with ~ / content /. The problem is that when html is generated, "~" is not included in the output, it is simply / content /.

 <img src="<%= Links.Content.Images.logo_png %>" alt="Logo" /> <img src="/Content/Images/logo.png" alt="Logo" /> 

Note:

The problem is that something is wrong with this line in web.config. It turns out that January 1, 2011 is not Friday, but Saturday. For some reason, I still didn't like this line.

 <clientCache httpExpires="Fri, 1 Jan 2011 15:30:00 UTC" cacheControlMode="UseExpires"/> 

Changing this to this works fine;

 <clientCache cacheControlMode="UseExpires" httpExpires="Tue, 19 Jan 2038 03:14:07 GMT" /> 

Add it here in the hope that it will help others solve this problem.

Thanks!

+4
source share
5 answers

This is unlikely to be a route or an IIS setup. The time I saw this, usually because resources are not available, i.e. Does not exist.

Also, sometimes security was set in the folder (s) that you are trying to access, and the default user .net was not granted access.

Resource paths are incorrectly encoded. using ~ / content instead of / content or even .. /../..etc can help.

+2
source

Ensure that the assembly actions are set to Content.

+1
source

Try checking permissions on the folder - are you in a non-standard folder (not wwwroot)? Verify that the IIS_IUSRS group has read and execute permissions for the folder and subfolders. If this does not work, try changing the permissions to temporarily give full access to everyone, just to find out if this is really a problem.

+1
source

Not sure if I understand the problem. It would be wrong if T4MVC gave the client ~ / the path, since ~ / is server-side syntax that browsers don’t understand. Note that you can change this processing if you want by going to T4MVC.settings.t4, which has:

 // You can change the ProcessVirtualPath method to modify the path that gets returned to the client. // eg you can prepend a domain, or append a query string: // return "http://localhost" + path + "?foo=bar"; private static string ProcessVirtualPathDefault(string virtualPath) { // The path that comes in starts with ~/ and must first be made absolute string path = VirtualPathUtility.ToAbsolute(virtualPath); // Add your own modifications here before returning the path return path; } 

So you can make it return whatever you want, but I don't think returning ~ / path will help you.

Perhaps I am a little misunderstanding the problem.

+1
source

Go to your website or web application β†’ Authentication β†’ Enable anonymous authentication. If this works, you can leave it if you like it, or configure permissions correctly.

0
source

Source: https://habr.com/ru/post/1299064/


All Articles