Replace Squishit with System.Web.Optimization in asp.net Web forms

Source: Internet
Author: User
Tags include reference

After upgrading a asp.net Web forms project from. NET Framework 4.0 to the. NET Framework 4.5, it was found that Squishit unexpectedly raised HTTP error 500.0-internal Server error.

Squishit is an open source support asp.net js/css Packaging tool, Project address: Https://github.com/jetheredge/SquishIt, born earlier than Microsoft ASP.net Web Optimization Framework (System.Web.Optimization).

Because Squishit does not support the. NET Framework 4.5, it can only be discarded instead of System.Web.Optimization.

The following are steps for using System.Web.Optimization in the actual asp.net Web forms project:

1. Add a reference to the Microsoft ASP.net Web optimization framework via NuGet

2. Add BundleConfig.cs to the App_Code

Using System.Web.Optimization;
    
public class Bundleconfig
{public
    static void Registerbundles (Bundlecollection bundles)
    {
        bundles. ADD (New Stylebundle ("~/bundles/news.css")
            . Include ("~/common/screen_base.css",
            "~/common/screen_news.css"));
    
        Bundles. ADD (New Scriptbundle ("~/bundles/news.js")
            . Include ("~/script/news_common.js", 
            "~/script/detail.js", 
            "~/script/share.js"));
    }

3. Add the following code to the Application_Start of Global.asax:

Bundleconfig.registerbundles (System.Web.Optimization.BundleTable.Bundles);

4. Add the following JS/CSS reference code in. aspx:

 

5. Operation Result:

<link href= "/bundles/news.css?v=swiyzt7yghul_fjj5uctlq6nk499bbwg7ev8krgojn01" rel= "stylesheet"/>
<script src= "/bundles/news.js?v=h7kknxn83hakcjjjw2vnezbw_hhg-e5saponos_2cx41" ></script>

The main differences between System.Web.Optimization and Squishit:

Squishit will generate the actual file saved in the corresponding path.

System.Web.Optimization only generates bundle files in memory.

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.