asp.net mvc 3 路由、资源
我使用路由
routes.MapRoute(
"Search",
"search/{categories}/{sections}/{actions}",
new { controller = "home", action = "search", categories = 0, sections = 0, actions = string.Empty }
);
示例: localhost:4304/search/64/0/0
在加载资源期间出现错误(500 或 404),因为 href="../../Content/Images/favicon.ico"
不执行 localhost:4304/Content/Images/favicon.ico
但执行localhost:4304/search/Content/Images/favicon.ico
(未找到)
所有资源(css、img、js)都有问题
i use route
routes.MapRoute(
"Search",
"search/{categories}/{sections}/{actions}",
new { controller = "home", action = "search", categories = 0, sections = 0, actions = string.Empty }
);
sample : localhost:4304/search/64/0/0
Error (500 or 404) during loading resources because the way href="../../Content/Images/favicon.ico"
conducts not to localhost:4304/Content/Images/favicon.ico
but conducts to localhost:4304/search/Content/Images/favicon.ico
(not found)
Problem with all resources (css, img, js)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样引用资源文件并不是一个好主意。最好的方法是通过以下方式吐出指向它们的链接:
如果您需要 CSS 中的任何图像,只需将它们放在 CSS 下的文件夹中(例如:~/Css/Images/myImage.jpg),以便您可以访问它们来自这样的CSS:
现在,话虽如此,favicon.ico 应该位于您网站的根目录中,而不是其他地方,您还有其他情况吗?
It's not a good idea to reference your resource files like that. The best way is to spit out links to them with:
And if you have any images that you need from CSS, just put them in a folder under CSS (example: ~/Css/Images/myImage.jpg) so you can access them from CSS like this:
Now, that being said, the favicon.ico should be in the root of your website and nowhere else, do you have some other situation?