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

发布于 2024-12-04 01:25:07 字数 438 浏览 1 评论 0原文

我有一个在 http://localhost/ 上运行的 ASP.NET MVC 3 网站。我还有一个新项目(ASP.NET MVC3),我想将其部署为应用程序 所以网址看起来像 http://localhost/child/

但我对图像有问题。如果我使用 logo 创建图像 该图像不可用,因为实际 URL 应为 /child/content/img/site-logo.png

如果我把 url 放入 Url.Content("~/content/img/site-logo.png") 就可以解决这个问题 但我现在不想改变我所有的图像。

有更简单的解决方案吗?一些 IIS 7 设置?

I have an ASP.NET MVC 3 website which is running on 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/

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.

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.

Is it some more easy solution? Some IIS 7 settings?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陌若浮生 2024-12-11 01:25:07

我遇到了同样的问题,但我找到了它强制对内容文件夹进行身份验证的原因。

当用户尚未登录时,他们被归类为匿名身份验证。在IIS7(我正在使用的,猜测IIS6中也是一样)中,您需要在功能视图中打开身份验证窗口。然后编辑匿名身份验证,以使用您的应用程序池身份或默认身份,只需确保用户有权读取该文件夹即可。

这为我解决了它,希望它对你有用。

I had the same issue, but I found the reason why it was forcing authentication on the Contents folder.

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

夕色琉璃 2024-12-11 01:25:07

只要输入url就可以解决
Url.Content("~/content/img/site-logo.png") 但我不想改变
现在我所有的图像。

除了将应用程序设置为在 IIS 网站的根目录运行之外,我不知道任何 IIS 设置。

在 ASP.NET MVC 应用程序中处理 url 时,应始终使用 url 帮助器。因此,您确实应该更改所有硬编码的 url,顺便说一下,这不仅包括图像,还可能是锚点 href、表单操作、javascript 文件中的硬编码 url,...

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.

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.

You should always use url helpers when dealing with urls in an ASP.NET MVC application. 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, ...

世界和平 2024-12-11 01:25:07

您可以在根iis项目中创建虚拟目录并将其指向包含图像的目录。但是,您最好花时间清理您的图像路径,因为它将来可能会再次咬您。

You can create virtual directory in root iis project and point it on directory with images. BUT, you should better spend this time to clean up your image paths because it, probably, will bite you in future again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文