mvc区域 Area 下css及js文件不能访问的解决

最近又有需要做网站的手机版,因此在areas下创建了MM,当做手机版访问页面。由于一些js及css文件与电脑版的有区别,所以我单独在/areas/MM下创建了scripts文件夹放置js文件,创建了Content文件夹放置css文件。在本地测试没有问题,但是挪到服务器上却发现网页访问不正常,加载不了内容。经过分析发现,原来是http://jiaogui.jinrimianshi.com/areas/mm/scripts/global.js和http://jiaogui.jinrimianshi.com/areas/mm/content/site.css报404未发现。严格按照创建的文件及文件夹的大小写来访问,并不能解决此问题。

百度搜索,没有任何答案。

google 搜索有一个在脚本链接中使用 @Url.Content,但是经过测试,问题依旧。还有一个建议,就是把css及js文件都放在areas区域外面。这个我不用试就知道可以,但我不想这样做。因为这css及js文件就是针对手机版的,放在外面总感觉怪怪的。而且在本地是没这个问题啊。

最后又在stackoverflow中找到一篇相关的文章:http://stackoverflow.com/questions/8062153/can-i-deploy-a-JavaScript-file-within-mvc-areas

这个文章提问题的人认可的答案是把js及css文件放置到areas外面。但我并不想采用。支持的理由就是我本地和另外一个网站有js及css文件放置到areas文件夹底下是可以正常访问的。

我看到了这篇文章介绍的另一个方法。就是在areas/mm/views底下的web.config中增加一些允许js,css文件访问的代码。

[html]  view plain  copy
  1. <system.web>  
  2.     <httpHandlers>  
  3.         <add path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />  
  4.         <add path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />  
  5.         <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>  
  6.     </httpHandlers>  
  7.     <!-- other content here -->  
  8. </system.web>  
  9.   
  10. <system.webServer>  
  11.     <handlers>  
  12.         <remove name="BlockViewHandler"/>  
  13.         <add name="JavaScript" path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />  
  14.         <add name="CSS" path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />  
  15.         <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />  
  16.     </handlers>  
  17.     <!-- other content here -->  
  18. </system.webServer>  

如果应用程序池是经典模式,则在system.web/httphandlers节点下增加:

<add path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />

如果是集成模式,则在system.webserver/handlers节点下增加:

<add path="*.js" verb="GET,HEAD" type="System.Web.StaticFileHandler" />
<add path="*.css" verb="GET,HEAD" type="System.Web.StaticFileHandler" />

我其实是不想加的,因为本地和另外一个网站我查了下,相应的web.config并没有相应的代码,但是却可以正常访问。但是实在没有办法,就想试试,由于我的是集成模式,因此我在system.webserver/handlers节点下增加了相应代码。然后就准备上床到服务器上。在上传到服务器上的时候,我发现我的本地areas/mm下的web.config在areas/mm/views目录下面,而服务器上的相应web.config文件却是在areas/mm下,我心里一动,想到不会是这里的问题吧。然后把服务器上areas/mm下的web.config挪到areas/mm/views下,并没有增加相应代码。尝试访问,正常了。原来是这里的问题。web.config位置放错造成的

地区码area.js大全 代码示例: var dsy = new Dsy(); dsy.add("0",["北京市","天津市","上海市","重庆市","河北省","山西省","内蒙古","辽宁省","吉林省","黑龙江省","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西","海南省","四川省","贵州省","云南省","西藏","陕西省","甘肃省","青海省","宁夏","新疆","香港","澳门","台湾省"]); dsy.add("0_0_0",["东城区","西城区","崇文区","宣武区","朝阳区","丰台区","石景山区","海淀区","门头沟区","房山区","通州区","顺义区","昌平区","大兴区","怀柔区","平谷区","密云县","延庆县","延庆镇"]); dsy.add("0_0",["北京市"]); dsy.add("0_1_0",["和平区","河东区","河西区","南开区","河北区","红桥区","塘沽区","汉沽区","大港区","东丽区","西青区","津南区","北辰区","武清区","宝坻区","蓟县","宁河县","芦台镇","静海县","静海镇"]); dsy.add("0_1",["天津市"]); dsy.add("0_2_0",["黄浦区","卢湾区","徐汇区","长宁区","静安区","普陀区","闸北区","虹口区","杨浦区","闵行区","宝山区","嘉定区","浦东新区","金山区","松江区","青浦区","南汇区","奉贤区","崇明县","城桥镇"]); dsy.add("0_2",["上海市"]); dsy.add("0_3_0",["渝中区","大渡口区","江北区","沙坪坝区","九龙坡区","南岸区","北碚区","万盛区","双桥区","渝北区","巴南区","万州区","涪陵区","黔江区","长寿区","合川市","永川区市","江津市","南川市","綦江县","潼南县","铜梁县","大足县","荣昌县","璧山县","垫江县","武隆县","丰都县","城口县","梁平县","开县","巫溪县","巫山县","奉节县","云阳县","忠县","石柱土家族自治县","彭水苗族土家族自治县","酉阳土家族苗族自治县","秀山土家族苗族自治县"]); dsy.add("0_3",["重庆市"]); ...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值