IIS7上的图像损坏

问题描述 投票:4回答:5

我有一个ASP.NET MVC站点,当我在本地运行时,它工作得很好。一旦我将该站点部署到IIS 7,所有资源链接都会被破坏(即脚本文件,图像,css文件)。这可能是路由问题还是IIS设置?

这是我的路线:

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
    );
}

编辑:

我使用T4MVC模板引用所有内容。当使用〜/ content /指定路径时,模板是正确的。问题是,当生成html时,输出不包括“〜”,它只是/ content /。

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

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

注意:

问题实际上是web.config中的这一行有问题。原来2011年1月1日不是星期五而是星期六。由于某种原因,它仍然不喜欢那条线。

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

将其更改为此工作正常;

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

在这里添加它希望它可以帮助其他人解决这个问题。

谢谢!

asp.net-mvc iis-7 t4mvc
5个回答
2
投票

它不太可能是路由或IIS设置。我所看到的这种情况通常是因为资源不可用,即不存在。

此外,有时还会设置您尝试访问的文件夹的安全性,并且默认的.net用户未被授予访问权限。

资源的路径编码不正确。使用〜/ content代替/ content甚至../../..etc可能会有所帮助。


1
投票

确保构建操作设置为“内容”。


1
投票

尝试检查您的文件夹权限 - 您是否在非标准文件夹(而不是wwwroot)?确保IIS_IUSRS组对文件夹和子文件夹具有读取和执行权限。如果这不起作用,请尝试更改权限以暂时向所有人提供完全控制,只是为了查看它是否是权限问题。


1
投票

我不确定我是否理解这个问题。 T4MVC输出〜/ path到客户端是错误的,因为〜/是浏览器不理解的服务器端语法。请注意,如果您愿意,可以通过转到T4MVC.settings.t4更改此处理,其中包含:

// You can change the ProcessVirtualPath method to modify the path that gets returned to the client.
// e.g. 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;
}

所以你可以让它返回你想要的任何东西,但我不认为返回〜/ path会帮助你。

我可能会误解这个问题。


0
投票

转到您的站点或Web应用程序 - >身份验证 - >启用匿名身份验证。如果这样做,你可以这样做,如果你没事,或正确调整权限。

© www.soinside.com 2019 - 2024. All rights reserved.