ASP.NET MVC 3 - 如果在 IIS 7.5 上部署为应用程序,则找不到图像
我有一个在 http://localhost/
上运行的 ASP.NET MVC 3 网站。我还有一个新项目(ASP.NET MVC3),我想将其部署为应用程序 所以网址看起来像 http://localhost/child/
但我对图像有问题。如果我使用 创建图像 该图像不可用,因为实际 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的问题,但我找到了它强制对内容文件夹进行身份验证的原因。
当用户尚未登录时,他们被归类为匿名身份验证。在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.
除了将应用程序设置为在 IIS 网站的根目录运行之外,我不知道任何 IIS 设置。
在 ASP.NET MVC 应用程序中处理 url 时,应始终使用 url 帮助器。因此,您确实应该更改所有硬编码的 url,顺便说一下,这不仅包括图像,还可能是锚点 href、表单操作、javascript 文件中的硬编码 url,...
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, ...
您可以在根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.