本文介绍了ASP.NET MVC 6(vNext)无法正常链接到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行ASP.NET MVC 5 6样品的项目,自定义的CSS文件。

I'm trying to run the ASP.NET 5 MVC 6 sample "HelloMVC" project, with a custom CSS file.

我把我的.css文件中的的wwwroot 文件夹,让我们在风格说文件夹中。

I place my .css files in the wwwroot folder, let's say in a styles folder.

我然后链接到它在我的 _Layout.cshtml

I then link to it in my _Layout.cshtml with

<link rel="stylesheet" href="~/styles/mystyle.css" />

不过,风格不会被渲染。

However, the style doesn't get rendered.

如果我去我的浏览器的预期文件的URL(比方说,我在12345端口上运行,所以我去的http://本地主机:12345 /风格/ mystyle.css ,我招呼着厚脸皮页面(纯HTML)与灯泡和一个笑脸,说:你的ASP.NET应用程序5已成功启动

If I go to the URL of the expected file in my browser (let's say I'm running on port 12345, so I go to http://localhost:12345/styles/mystyle.css, I'm greeted with a cheeky page (pure HTML) with a lightbulb and a smiley face that says "Your ASP.NET 5 application has been successfully started".

事实上,如果我去的任何的URL正在运行的应用程序,我招呼着相同的页面。即要的http://本地主机:12345 / thisfiledoesntexist.jpg 将返回相同的页面

In fact, if I go to any URL for the running app, I'm greeted with the same page. i.e. going to http://localhost:12345/thisfiledoesntexist.jpg will return the same page.

这是ASP.NET 5的电流 404 页?为什么不是我的风格越来越呈现?我认为这将是一个非常简单的事情。

Is this ASP.NET 5's current 404 page? Why aren't my styles getting rendered? I would think this would be a very simple thing.

展望href=\"http://stackoverflow.com/questions/27648045/what-is-wwwroot-in-asp-net-vnext\">这个问题似乎有什么我这样做是正确的方式。事实上,Visual Studio中甚至有打字出来的HREF时我已经添加了css文件智能感知。

Looking at this question it seems that what I'm doing would be the proper way. In fact, Visual Studio even has intellisense for the css files that I've added when typing out the href.

推荐答案

删除 app.UseWelcomePage(); Startup.cs 固定这一点,因为每建议(和有用链接的)

Removing app.UseWelcomePage(); from Startup.cs fixed this, as per Sami Kuhmonen's suggestion (and helpful link to https://github.com/aspnet/Home/issues/113)

这篇关于ASP.NET MVC 6(vNext)无法正常链接到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 08:00