如何在MVC3中过滤和压缩输出HTML?

时间:2012-12-12 17:07:22

标签: html vb.net asp.net-mvc-3 action-filter global-filter

在我的MVC3项目中,所有页面都有以下HTML作为输出

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>My app</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="author" content="">
    <link href="/Content/bootstrap.min.css" rel="stylesheet">
    <link href="/Content/bootstrap-responsive.min.css" rel="stylesheet">
    <!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link rel="shortcut icon" href="/Content/icons/favicon.ico">
    <link rel="apple-touch-icon-precomposed" sizes="144x144" href="/Content/icons/apple-touch-icon-144-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="114x114" href="/Content/icons/apple-touch-icon-114-precomposed.png">
    <link rel="apple-touch-icon-precomposed" sizes="72x72" href="/Content/icons/apple-touch-icon-72-precomposed.png">
    <link rel="apple-touch-icon-precomposed" href="/Content/icons/apple-touch-icon-57-precomposed.png">
  </head>

  <body>

    <div class="container-fluid">
      <div class="row-fluid">
        <div class="span12">
          <div class="well">
            <h2>Test</h2>
          </div>
        </div>
      </div>
      <hr>
      <footer>
        <p>&copy;</p>
      </footer>
    </div>
    <script src="/Scripts/jquery-1.8.2.min.js"></script>
    <script src="/Scripts/bootstrap.min.js"></script>
  </body>
</html>

但是,我如何制作一个过滤器来修剪行并删除空行,以获得如下例所示的输出......

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My app</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<link href="/Content/bootstrap.min.css" rel="stylesheet">
<link href="/Content/bootstrap-responsive.min.css" rel="stylesheet">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link rel="shortcut icon" href="/Content/icons/favicon.ico">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/Content/icons/apple-touch-icon-144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/Content/icons/apple-touch-icon-114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="/Content/icons/apple-touch-icon-72-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="/Content/icons/apple-touch-icon-57-precomposed.png">
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div class="well">
<h2>Test</h2>
</div>
</div>
</div>
<hr>
<footer>
<p>&copy;</p>
</footer>
</div>
<script src="/Scripts/jquery-1.8.2.min.js"></script>
<script src="/Scripts/bootstrap.min.js"></script>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

在ASP.NET MVC中, 你可以使用动作过滤器,缓存&amp;压缩以快速加载您的网站。

请查看链接filter caching and compression (C#)

希望它对你有用