ASP。NET MVC要求我重新认证PNG文件,而不是gif或jpeg文件

时间:2022-09-03 20:34:43

For some reason, any time I reference a PNG from my application.css file, I get prompted for credentials. However, I can reference GIFs, JPEGs, etc. from my images directory without a problem.

出于某种原因,我在任何时候都会从我的应用程序中引用PNG。css文件,提示我要凭证。但是,我可以从我的图像目录中引用gif、jpeg等,没有问题。

My routes are set up like this:

我的路线是这样设置的:

public static void RegisterRoutesTo(RouteCollection routes) {

        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
        routes.IgnoreRoute("elmah.axd");
        routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });

        routes.MapRoute(
            "Default", "",                   
            new { controller = "Home", action = "Index"}  // Parameter defaults
        );

        routes.MapRoute(
            "Session", "{action}",
            new { controller = "Session" },
            new { action = "(login|logout|register)" }
        );

        routes.MapRoute("CatchAll",  "{*catchall}",
            new { controller = "Error", action = "NotFound" });
    }

In my CSS, I have this:

在我的CSS中,我有:

.iconLocationLarge { background-image: url(../images/icon_vcarea_48x48.png) !important;}
.iconVCLarge { background-image: url(../images/tb-btn-sprite.gif) !important;}

The problem is that I get prompted to authenticate again if I use a PNG but not with the GIF. Why?

问题是,如果我使用PNG而不是GIF,系统会提示我再次进行身份验证。为什么?

3 个解决方案

#1


2  

IIS can serve content directly without passing the request to ASP.NET. I suspect in your case that IIS is set to serve GIF and JPG but not PNG. See for example http://mvolo.com/blogs/serverside/archive/2006/11/10/Stopping-hot_2D00_linking-with-IIS-and-ASP.NET.aspx for a discussion on the topic. See also http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/4c840252-fab7-427e-a197-7facb6649106.mspx?mfr=true.

IIS可以直接提供内容,而不会将请求传递给ASP.NET。我怀疑在你的情况下IIS被设置为服务GIF和JPG而不是PNG。例如,请参见http://mvolo.com/blogs/serverside/archive/2006/11/10/stopping - hot_2d00_linking - iisand - asp.net.aspx,以讨论这个主题。参见http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/iis/4c840252 fab7 - 427 e - a197 facb6649106.mspx?mfr=true——7。

Assuming this is IIS6, open the IIS Manager from Administrative Tools, right click on the local computer node, click on MIME types, check that PNG is registered as "image/png". You can also configure this at the individual web site level.

假设这是IIS6,从管理工具中打开IIS管理器,右键单击本地计算机节点,单击MIME类型,检查PNG是否注册为“image/ PNG”。您还可以在单独的web站点级别配置它。

Make sure there is no other filter that could cause the issue, e.g. the UrlScan ISAPI filter.

确保没有其他可能导致问题的过滤器,例如UrlScan ISAPI过滤器。

#2


2  

Finally solved:

终于解决了:

The PNG files I was referencing were encrypted. That is it.

我引用的PNG文件是加密的。就是这样。

After finally exhausting all other options with IIS and ASP.NET I noticed that each PNG file I was referencing had the attributes "AE" (E= Encrypted). So the solution was to right-click the folder, click "Advanced" button and de-select the "Encryption" option.

在使用IIS和ASP完成所有其他选项之后。我注意到我引用的每个PNG文件都有“AE”属性(E=加密)。因此,解决方案是右键单击文件夹,单击“高级”按钮并取消选择“加密”选项。

#3


0  

I am not sure why, but probably you should add ignore routes for all static content regardless.

我不知道为什么,但是您应该为所有静态内容添加忽略路由。

ASP.NET MVC thinks my virtual directory is a controller

ASP。NET MVC认为我的虚拟目录是一个控制器。

#1


2  

IIS can serve content directly without passing the request to ASP.NET. I suspect in your case that IIS is set to serve GIF and JPG but not PNG. See for example http://mvolo.com/blogs/serverside/archive/2006/11/10/Stopping-hot_2D00_linking-with-IIS-and-ASP.NET.aspx for a discussion on the topic. See also http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/4c840252-fab7-427e-a197-7facb6649106.mspx?mfr=true.

IIS可以直接提供内容,而不会将请求传递给ASP.NET。我怀疑在你的情况下IIS被设置为服务GIF和JPG而不是PNG。例如,请参见http://mvolo.com/blogs/serverside/archive/2006/11/10/stopping - hot_2d00_linking - iisand - asp.net.aspx,以讨论这个主题。参见http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/iis/4c840252 fab7 - 427 e - a197 facb6649106.mspx?mfr=true——7。

Assuming this is IIS6, open the IIS Manager from Administrative Tools, right click on the local computer node, click on MIME types, check that PNG is registered as "image/png". You can also configure this at the individual web site level.

假设这是IIS6,从管理工具中打开IIS管理器,右键单击本地计算机节点,单击MIME类型,检查PNG是否注册为“image/ PNG”。您还可以在单独的web站点级别配置它。

Make sure there is no other filter that could cause the issue, e.g. the UrlScan ISAPI filter.

确保没有其他可能导致问题的过滤器,例如UrlScan ISAPI过滤器。

#2


2  

Finally solved:

终于解决了:

The PNG files I was referencing were encrypted. That is it.

我引用的PNG文件是加密的。就是这样。

After finally exhausting all other options with IIS and ASP.NET I noticed that each PNG file I was referencing had the attributes "AE" (E= Encrypted). So the solution was to right-click the folder, click "Advanced" button and de-select the "Encryption" option.

在使用IIS和ASP完成所有其他选项之后。我注意到我引用的每个PNG文件都有“AE”属性(E=加密)。因此,解决方案是右键单击文件夹,单击“高级”按钮并取消选择“加密”选项。

#3


0  

I am not sure why, but probably you should add ignore routes for all static content regardless.

我不知道为什么,但是您应该为所有静态内容添加忽略路由。

ASP.NET MVC thinks my virtual directory is a controller

ASP。NET MVC认为我的虚拟目录是一个控制器。