asp.net mvc 3 路由、资源

发布于 2024-11-09 06:26:10 字数 591 浏览 0 评论 0原文

我使用路由

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 技术交流群。

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

发布评论

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

评论(1

二智少女猫性小仙女 2024-11-16 06:26:10

像这样引用资源文件并不是一个好主意。最好的方法是通过以下方式吐出指向它们的链接:

@Url.Content("~/Css/etc.css")

如果您需要 CSS 中的任何图像,只需将它们放在 CSS 下的文件夹中(例如:~/Css/Images/myImage.jpg),以便您可以访问它们来自这样的CSS:

background-image: url(Images/myImage.jpg)

现在,话虽如此,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:

@Url.Content("~/Css/etc.css")

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:

background-image: url(Images/myImage.jpg)

Now, that being said, the favicon.ico should be in the root of your website and nowhere else, do you have some other situation?

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