在IIS托管的asp.net MVC站点中未分发包括CSS在内的文件 [英] Files including css refered not dispalyed in IIS hosted asp.net MVC site
问题描述
我的图像,css和任何其他引用的文件未显示在我的本地托管站点中.但是在运行时一切正常.
我引用的文件是
"../../FoodImages/abcd.jpg"
如果我的项目名称为ProjectTest,则在我的Visual Studio中,其层次结构为ProjectTest/FoodImages/abcd.jpg.它可以正常工作.如果我将项目发布到MySite文件夹中,则FoodImages文件夹的名称类似于MySite/FoodImages/abcd. jpg.
我的Site.css也是如此,
我已经引用过
< link href ="../../Content/Site.css" rel ="stylesheet" type ="text/css"/>
我试过使用``〜'',但是都没有用.例如:
返回File(Server.MapPath(〜/Documents/menu.pdf"),contentType:"application/pdf");
请帮帮我.不托管时,它可以正常工作.
My images ,css,and any other referred files are not displayed in my locally hosted site.but while running everything is proper.
I refer files like
"../../FoodImages/abcd.jpg"
If my project name is ProjectTest,in My visual studio heirarchical structure is ProjectTest/FoodImages/abcd.jpg.And it is properly working.If i had published my project to a folder MySite,the folder FoodImages comes like MySite/FoodImages/abcd.jpg.
Same is the case with my Site.css,
I have refered like
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
I have tried using ''~'',but it neither worked.for eg:
return File(Server.MapPath("~/Documents/menu.pdf"), contentType:"application/pdf");
Please help me out.Its properly working when not hosted.
推荐答案
这是MVC部署中的常见问题.请尝试更改参考,如下所示.
It''s a common problem in the MVC deployment. Please try to change the reference like the following.
<link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css"/>
注意:
Note:
<link href="../../Content/Site.css" rel="stylesheet" type="text/css" />
仅在开发环境中有效.
如果遇到任何问题,请回复.
will work only in devlopment environment.
Please revert back, if you face any issue.
这篇关于在IIS托管的asp.net MVC站点中未分发包括CSS在内的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!