简体   繁体   English

ASP.NET MVC 3 - 如果在IIS 7.5上部署为应用程序,则找不到图像

[英]ASP.NET MVC 3 - Images not found if deploy as application on IIS 7.5

I have an ASP.NET MVC 3 website which is running on http://localhost/ . 我有一个ASP.NET MVC 3网站,它运行在http://localhost/ I also have a new project (ASP.NET MVC3) and I want to deploy it as application so the url will look like http://localhost/child/ 我还有一个新项目(ASP.NET MVC3),我想将其部署为应用程序,因此url看起来像http://localhost/child/

But I have problems with images. 但我的图像有问题。 If I create image using <img src="/content/img/site-logo.png" alt="logo" /> the image is not available, because the actual URL should be /child/content/img/site-logo.png . 如果我使用<img src="/content/img/site-logo.png" alt="logo" />图像,则图片不可用,因为实际的网址应为/child/content/img/site-logo.png

I can solve it if I put url in Url.Content("~/content/img/site-logo.png") but I don't want to change all my images now. 如果我把url放在Url.Content("~/content/img/site-logo.png")我可以解决它,但我现在不想改变我的所有图像。

Is it some more easy solution? 这是一个更简单的解决方案吗? Some IIS 7 settings? 一些IIS 7设置?

I had the same issue, but I found the reason why it was forcing authentication on the Contents folder. 我遇到了同样的问题,但我发现它在Contents文件夹中强制进行身份验证的原因。

When a user is not logged in yet, they are classified as Anonymous Authentication. 当用户尚未登录时,它们被归类为匿名身份验证。 In IIS7 (which is what I am using, guessing it is the same in IIS6) you need to open the authentication window in features view. 在IIS7中(我正在使用它,猜测它在IIS6中是相同的)您需要在功能视图中打开身份验证窗口。 Then edit the Anonymous Authentication, to use your application pool identity, or the default one, just make sure that user has permissions to read in that folder. 然后编辑匿名身份验证,使用您的应用程序池标识或默认身份验证,只需确保该用户有权读取该文件夹。

That fixed it for me, hope it works for you. 这对我来说是固定的,希望它适合你。

I can solve it if I put url in Url.Content("~/content/img/site-logo.png") but I don't want to change all my images now. 如果我把url放在Url.Content(“〜/ content / img / site-logo.png”)中我可以解决它,但我现在不想改变我的所有图像。

I am not aware of any IIS setting, other than of course setting your application to run at the root of the IIS web site. 我不知道任何IIS设置,除了当然将应用程序设置为在IIS网站的根目录下运行。

You should always use url helpers when dealing with urls in an ASP.NET MVC application. 在ASP.NET MVC应用程序中处理URL时,应始终使用url帮助程序。 So you really should change all hardcoded urls, and by the way this doesn't include only images, it could be also anchor hrefs, form actions, hardcoded urls in your javascript files, ... 所以你真的应该改变所有硬编码的网址,顺便说一下,这不包括图像,它也可以是你的javascript文件中的锚点href,表单动作,硬编码网址,...

You can create virtual directory in root iis project and point it on directory with images. 您可以在root iis项目中创建虚拟目录,并将其指向带有图像的目录。 BUT, you should better spend this time to clean up your image paths because it, probably, will bite you in future again. 但是,你应该花更多的时间来清理你的图像路径,因为它可能会在将来再次咬你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM