MVC + IIS7 = CSS问题 [英] MVC + IIS7 = CSS Issue

查看:124
本文介绍了MVC + IIS7 = CSS问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站通过IIS7在Vista上运行。该网站在端口88上运行,所以的http://本地主机:88 应该呈现缺省的/首页/索引视图。

I have a web site running via IIS7 on Vista. The site is running on port 88, so http://localhost:88 should render the default /Home/Index view.

这正常工作,像所有其他的意见。

This works correctly, as do all other views.

然而,一个问题是居民。我的脚本路径指向/脚本/ [文件],我的CSS路径指向/内容/ [文件]。我的假设是,/内容或/ Scripts文件夹将始终在站点的根目录下,我不打算执行这个网站的虚拟目录设置。每当网页渲染,他们没有的CSS或脚本!所以,一切看起来靠不住的和脚本显然是行不通的,所以就有很多的意见都不能工作。

However, one problem is resident. My script paths point to /Scripts/[FILE] and my CSS paths point to /Content/[FILE]. My assumption was that the /Content or /Scripts folder would always be at the root of the site as I have no intention to run this site in a virtual directory setting. Whenever the pages render, they have NO CSS or script! So everything looks wonky and the scripting obviously doesn't work, hence a lot of the views don't work either.

这是一个很奇怪的问题,一个我敢肯定,是我缺乏IIS7主办下认识事物的结果。我倒是AP preciate任何帮助,任何人都可以提供。非常感谢!

This is a very odd problem, one that I'm sure is a result of my lack of knowledge hosting things under IIS7. I'd appreciate any help anyone could offer. Thanks a lot!

推荐答案

我希望这个线程的延续传达的意愿,以确保这个问题不会开车的人落悬崖。有很多在有关解决在Vista上这个问题的各种论坛的文件,但我无法找到任何2K8同样的文章。正如本论坛后表示我能确定对问题Vista的机器。唉,一个像执行未能解决在2K8此事。

I hope the continuation of this thread conveys a willingness to make sure this problem doesn't drive anyone off the cliff. There's a lot of documentation in various forums about solving this issue on Vista but I couldn't find any likewise articles for 2K8. As indicated in this forum post I was able to fix the issue on a Vista machine. Alas, a like execution failed to resolve the matter on 2K8.

我已经验证了StaticFileHandler已被列入在web.config <一个href=\"http://www.apijunkie.com/APIJunkie/blog/post/2007/11/Breaking-changes-in-ASPNet-20-HTTP-Handlers-when-moving-from-IIS5-on-Windows-2000-to-IIS6-on-Windows-2003.aspx\"相对=nofollow>在这个博客帖子在apijunkie.com 建议。不过,没有运气。

I had verified that the StaticFileHandler had been included in the web.config as suggested in this blog post at apijunkie.com. Still, no luck.

洁肤的没有运气,在这里的 - 我的服务器端功能是完美的。所有的MVC路线的工作就像一个冠军。只是所有的CSS和JS渲染失败。当浏览器直接指向CSS或结果页面的JS文件是一个ASP.NET 404,而不是的传统的的404错误页面。

Clarifying no luck, here - My server-side functionality was perfect. All MVC routes work like a champ. Just all CSS and JS rendering failed. When browser pointed directly at CSS or JS files resulting page was an ASP.NET 404 and not the traditional 404 error page.

于是我走进IIS7管理器,进入处理程序映射对话框。我补充说,指定的System.Web.StaticFileHandler类型并赋予它* .CSS的扩展,新的处理程序。然后,我重复,对于* .JS,* .png和* .gif文件。当我在浏览器中刷新该网站,一切perectly渲染。下面的屏幕截图展示了这一过程。

So I went into the IIS7 Manager and into the Handler Mappings dialog. I added a new handler that specified the System.Web.StaticFileHandler type and gave it an extension of *.CSS. Then I repeated that for *.JS, *.PNG, and *.GIF files. When I refreshed the site in the browser, everything rendered perectly. The screen shots below demonstrate this process.

的处理程序映射窗口:

添加一个新的托管处理程序

Adding a new Managed Handler

这解决了这个问题,现在我在W2K主办的充分发挥功能的MVC应用程序。时间一吉尼斯。

This resolved the problem, and now I have a perfectly functioning MVC app hosted in W2K. Time for a Guinness.

这篇关于MVC + IIS7 = CSS问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆