建立 MVC的模板頁,引用多個Css(期間,產生 HTTP 錯誤 500.23 - Internal Server Error   檢測到在整合的託管管道模式下不適用的 ASP.NET 設定。)

來源:互聯網
上載者:User

標籤:ons   版本   asp.net   dex   clu   運行   routes   .com   mod   

 

 

首先,建立一個_Layut.cshtml的模板頁

@using System.Web.Optimization<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>666</title>    @Styles.Render("~/Content/Css/css")    </head><body>    <div>        @RenderBody()    </div></body></html>

這裡頭,需要引用 Optimization,可以在NuGet裡面尋找引用(Microsoft.AspNet.Web.Optimization)

然後,在App_Start中建立一個BundleConfig.cs

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Optimization;namespace InsusMvc.NET{    public class BundleConfig    {        public static void RegisterBundles(BundleCollection bundles)        {            bundles.Add(new StyleBundle("~/Content/Css/css").Include(                "~/Content/Css/StyleSheet1.css",
          "~/Content/Css/StyleSheet2.css"//這個是我路徑下的css,多個的話,可以繼續加下去,其間用逗號(英文)隔開 )); } }}

之後,在View檔案夾裡面的web.config添加namespace

 

後年,在Global.asax中添加  BundleConfig.RegisterBundles(BundleTable.Bundles); 

using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using System.Web.Routing;using System.Web.Optimization;using InsusMvc.NET;namespace InsusMvc{    public class MvcApplication : System.Web.HttpApplication    {        protected void Application_Start()        {            AreaRegistration.RegisterAllAreas();            RouteConfig.RegisterRoutes(RouteTable.Routes);            BundleConfig.RegisterBundles(BundleTable.Bundles);//添加這個(使用我們上面添加的BundleConfig.cs)        }    }}

最後,配置完成,建立個 Index.cshtml頁面來試試

@{    Layout = "~/Layout/_Layout.cshtml";}<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title></head><body>    <div class="title">         kankan    </div></body></html>

當然,不採用模板頁也可以

@{    Layout = null;}<!DOCTYPE html><html><head>    <meta name="viewport" content="width=device-width" />    <title>Index</title>    @Styles.Render("~/Content/Css/css")</head><body>    <div class="title">         kankan    </div></body></html>

 

之後,運行,出現

我個暈了,查下,原因是:

 

在IIS7的應用程式集區有兩種模式,一種是“整合模式”,一種是“傳統模式”。

傳統模式 則是我們以前習慣的IIS 6 的方式。

如果使用整合模式,那麼對自訂的httpModules 和 httpHandlers 就要修改設定檔,需要將他們轉移到<modules>和<hanlders>節裡去。

 

上面這段是百度的看到的(不理解)

 

得到解決方案,有兩個,

第一種:

將IIS的程式應用池修改成傳統模式

這個我是本地運行VS版本的,不懂得修改,感覺很麻煩,跳過

第二種:

直接在Web.Config裡面禁止驗證整合錯誤

在system.webServer中添加   validation validateIntegratedModeConfiguration="false" />

 

最終,運行結果

 

 

 

 

感謝:

http://blog.csdn.net/a351945755/article/details/21000453

http://www.cnblogs.com/vingi/articles/2868933.html

http://www.cnblogs.com/insus/p/3360918.html

 

建立 MVC的模板頁,引用多個Css(期間,產生 HTTP 錯誤 500.23 - Internal Server Error   檢測到在整合的託管管道模式下不適用的 ASP.NET 設定。)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.