It's probally not working in MVC 4

Nov 14, 2013 at 7:39 AM
I'm just tried to use this MVC Extensions and I see no evidance of result. Maybe I'm doing something wrong. I'm just installed it from nuget and attribute [MinifyHtml] to my method. Can you help me?
Coordinator
Nov 14, 2013 at 9:07 AM
Hello, Sntlv!

Switch a web application to release mode by using the following settings in the Web.config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  …
  <system.web>
    <compilation debug="false"  … />
    …
  </system.web>
  …
</configuration>
Nov 14, 2013 at 10:22 AM
I tried that too. Changed build mode, no result. Anything else?
P.S.: Thank you in advance.
Coordinator
Nov 14, 2013 at 10:38 AM
Try to read documentation and explore a example project (WebMarkupMin.Example.Mvc).
Nov 14, 2013 at 11:20 AM
Copied all html/ core and webextension part of config andd add only [minifyhtml] attribute, run release mode - no result. Read all docs and looked through project. Maybe I need some magic?
Nov 14, 2013 at 11:26 AM
Is it it suppose to work with IIS Express?
Coordinator
Nov 14, 2013 at 11:28 AM
Try significantly increase the value of maxResponseSize property:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
   …
   <webMarkupMin xmlns="http://tempuri.org/WebMarkupMin.Configuration.xsd">
      …
      <webExtensions maxResponseSize="…" />
      …
   </webMarkupMin>
   …
</configuration>
Nov 14, 2013 at 11:33 AM
maxResponseSize="5000000" still nothing =))
Nov 14, 2013 at 11:40 AM
But your project is doing good. I downloaded it and tried out on IIS Express.
Coordinator
Nov 14, 2013 at 11:42 AM
IIS Express is supported.

Frankly, I don't know why you have these errors. Create a new ASP.NET MVC application, and try to install WebMarkupMin.Mvc.
Nov 14, 2013 at 11:42 AM
Is it working with .Net Framework 4.5?
Coordinator
Nov 14, 2013 at 11:44 AM
.Net Framework 4.5 and 4.5.1 is supported.

May be you are using a CMS?
Coordinator
Nov 14, 2013 at 11:47 AM
MVC 4 is supported.
Coordinator
Nov 14, 2013 at 11:48 AM
CREATE A NEW ASP.NET MVC APPLICATION, AND TRY TO INSTALL WEBMARKUPMIN.MVC!!!
Nov 14, 2013 at 11:48 AM
Hmm, no, I'm not. How can I debug this or what are known issues? For me it is just not working at all, no errors. But in your test project everything is fine.
Nov 14, 2013 at 11:49 AM
OK, I'll try =))
Coordinator
Nov 14, 2013 at 11:52 AM
Make your test project on the basis of ASP.NET MVC 4 and .NET Framework 4.5.
Nov 14, 2013 at 11:55 AM
Still not working even in a newly created web app. I can send it if you want.
Coordinator
Nov 14, 2013 at 11:59 AM
Waiting for your test project.
Nov 14, 2013 at 12:04 PM
Coordinator
Nov 14, 2013 at 12:10 PM
Do you speak Russian?
Nov 14, 2013 at 12:12 PM
Конечно =))
Coordinator
Nov 14, 2013 at 12:19 PM
А что это у нас в Web.config написано?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  …
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    …
  </system.web>
  …
</configuration>
Coordinator
Nov 14, 2013 at 12:24 PM
Артем!

У меня только 2 объяснения:
  1. Ты троллишь мой проект.
  2. Ты совсем не внимательный.
Nov 14, 2013 at 12:24 PM
Я запускал с релизом и с debug="false". Попробуйте сами.
Coordinator
Nov 14, 2013 at 12:26 PM
Попробовал и у меня работает.
Coordinator
Nov 14, 2013 at 12:30 PM
У тебя наверное и скрипты со стилями не минимизируются?
Nov 14, 2013 at 12:37 PM
Странно, у меня тоже заработало. Прости, если отвлекаю. Но сначала оно не работало, правда. Теперь не работает только в основном проекте. Если я мешаю, я могу сам поэкмпериментировать.
Nov 14, 2013 at 12:39 PM
Скрипты и стили я отдельно минимизирую при сборке проекта. Вот решил попробовать HTML минимизировать. Уже пол дня бьюсь, не получается. Видимо совсем руки кривые у меня =))
Coordinator
Nov 14, 2013 at 12:45 PM
Закрываем обсуждение.

У меня есть статьи про WebMarkupMin на русском: «WebMarkupMin HTML Minifier – современный HTML-минимизатор для платформы .NET» и «HTML-минимизация в Web Essentials 2013».
Mar 8, 2014 at 8:21 AM
Hi,

Thanks for creating and sharing this. Does this work if I am using a CMS? I get a reflection load error after installing.
Coordinator
Mar 8, 2014 at 8:27 AM
Hello, Austin!

Describe error in detail.
Mar 9, 2014 at 2:45 AM
Edited Mar 9, 2014 at 2:49 AM
Thanks for your reply.

Can you confirm that this library with work with a CMS? You asked a question above "Are you using CMS?". I am using Sitefinity from Telerik. It has the capability to run WebPages and MVC and WebPages/MVC Hybrid. I see no reason why it should not work it is standard ASP.net after all.

In the setup I was testing I had a MasterPage that I modified to be derived from MinifiedAndCompressedHtmlPage.

Here is the exception that is thrown when I tried to compile the solution after adding WebMarkupMin via Nuget.

Error 114 Unable to load assembly 'SitefinityWebApp, Version=6.3.5000.0, Culture=neutral, PublicKeyToken=null' : Could not load file or assembly 'WebMarkupMin.Core, Version=0.8.2.0, Culture=neutral, PublicKeyToken=99472178d266584b' or one of its dependencies. General Exception (Exception from HRESULT: 0x80131500)
ExceptionString:
System.SystemException: Unable to load assembly 'SitefinityWebApp, Version=6.3.5000.0, Culture=neutral, PublicKeyToken=null' : Could not load file or assembly 'WebMarkupMin.Core, Version=0.8.2.0, Culture=neutral, PublicKeyToken=99472178d266584b' or one of its dependencies. General Exception (Exception from HRESULT: 0x80131500) ---> System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at Telerik.OpenAccess.Metadata.MetadataAttributesReader.PrepareMetaModelTypes(Assembly assembly)
--- End of inner exception stack trace ---
at Telerik.OpenAccess.Metadata.MetadataAttributesReader.PrepareMetaModelTypes(Assembly assembly)
at Telerik.OpenAccess.Metadata.MetadataAttributesReader.ReadMetaModel(Assembly assembly)
at Telerik.OpenAccess.Metadata.AttributesMetadataSource.<>c__DisplayClass1.<FromAssembly>b__0()
at Telerik.OpenAccess.Metadata.AttributesMetadataSource.CreateModel()
at Telerik.OpenAccess.Metadata.MetadataSource.GetModelCore(MetadataContainer old)
at Telerik.OpenAccess.Sdk.Enhancer.Enhancer.CrossDomainRunImpl(AssemblyLoader assemblyLoader)
at Telerik.OpenAccess.Sdk.Enhancer.EnhancerBase.CrossDomainRun() C:\Dev\MAIN\Source\SitefinityWebApp\obj\Debug\SitefinityWebApp.dll SitefinityWebApp

The solution is being compiled against .net 4.5.1 AnyCpu.

I temporaily removed the libary and rolled back to an alternative solution, but I would love to get this working since WebMarkupMin seems to have some really nice features.

I am also starting out to use your excellent BundleTransforms project. I had concerns about whether or not WebMarkupMIn would double up the minification that was going on. I came to the conclusion that WebMarkupMIn would only minify and compress pages served by Sitefinity and any inline scripts or styles that appeared on that page and that BundleTransforms would minify any externally referenced scripts and styles. Is this conclusion correct?

Thanks!
Coordinator
Mar 9, 2014 at 5:58 AM
What modules you are using in the project: WebMarkupMin.Web, WebMarkupMin.Mvc or WebMarkupMin.WebForms?

WebMarkupMin only minify inline scripts or styles. For external scripts and styles you should use the another solution (for example, Bundle Transformer).
Coordinator
Mar 9, 2014 at 6:27 AM
About the error: it seems to me that you have updated WebMarkupMin.Core to the latest version and forgot to move in the Web.config file the following settings:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  …
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      …
      <dependentAssembly>
        <assemblyIdentity name="WebMarkupMin.Core" publicKeyToken="99472178d266584b" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-0.8.13.0" newVersion="0.8.13.0" />
      </dependentAssembly>
      …
    </assemblyBinding>
  </runtime>
  …
</configuration>
Mar 9, 2014 at 11:30 AM
Due to the fact that Sitefinity supports Webforms MVC and Hybrid I actually installed.

Minifier.Core
Minifer.MsAjax
Minifier.Web.Extensions
Minifier.ASP.NET MVC Extensions
Minifier.ASP.NET Web Forms Extension

I assumed that since I just installed from Nuget it would auotmatically apply the latest version. I do not recall upgrading.

I'll give it another try with the binding redirect. Hopefully that will get me going with this.

Thanks again.
Mar 14, 2014 at 10:16 PM
Just given this another try. Still get the same error. The binding redirect was automatically added to the web.config.

My refrences look like the following.
<Reference Include="WebMarkupMin.Core">
  <HintPath>..\packages\WebMarkupMin.Core.0.8.13\lib\net40\WebMarkupMin.Core.dll</HintPath>
</Reference>
<Reference Include="WebMarkupMin.MsAjax">
  <HintPath>..\packages\WebMarkupMin.MsAjax.0.8.16\lib\net40\WebMarkupMin.MsAjax.dll</HintPath>
</Reference>
<Reference Include="WebMarkupMin.Mvc">
  <HintPath>..\packages\WebMarkupMin.Mvc.0.8.1\lib\net40\WebMarkupMin.Mvc.dll</HintPath>
</Reference>
<Reference Include="WebMarkupMin.Web">
  <HintPath>..\packages\WebMarkupMin.Web.0.8.1\lib\net40\WebMarkupMin.Web.dll</HintPath>
</Reference>
<Reference Include="WebMarkupMin.WebForms">
  <HintPath>..\packages\WebMarkupMin.WebForms.0.8.2\lib\net40\WebMarkupMin.WebForms.dll</HintPath>
</Reference>
Maybe I need to compile the source against .net 4.5.1 AnyCPU? Other than that I am at a loss as to why this is not working.
Coordinator
Mar 15, 2014 at 1:28 PM
Give me an example of code, that uses WebMarkupMin.
Mar 15, 2014 at 5:20 PM
Edited Mar 16, 2014 at 11:03 AM
The only test that I have run so far is a WebForms master template that is used for the site theme.
<%@ Master Language="C#"   Inherits="SitefinityWebApp.App_Data.Sitefinity.WebsiteTemplates.EC.App_Master.main" CodeFile="main.master.aspx.cs"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js" language="javascript"></script>
    <script src="/Scripts/jquery.easing.1.3.js"></script>
    <script src="/Scripts/jquery.mousewheel-3.0.6.pack.js"></script>
    <script src="/Scripts/jquery.fancybox.js"></script>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" /> 
    <meta http-equiv="content-language" content="en-gb">
    <link runat="server" rel="shortcut icon" href="~/favicon.ico" type="image/x-icon" />
<link runat="server" rel="icon" href="~/favicon.ico" type="image/ico" />
  

    <!--[if IE]>
        <link href="/Sitefinity/WebsiteTemplates/EC/App_Themes/EC/Styles/internet_explorer.css" rel="stylesheet" type="text/css" />
    <![endif]-->

</head>
<body class="main-body">
    <form id="form1" runat="server">     
<asp:ScriptManager ID="ScriptManager1" runat="server" />    
        <div id="wrapper">
            <div id="userstrip-holder">
                <div id="userstrip">
                    <asp:contentplaceholder id="userstrip" runat="server" />

                </div>
                <div id="toggle">
                    <%--<asp:Literal id="mylit" Text="<%$Resources:Labels, toggle_user_menu %>" runat="server"/>--%>
                    <asp:Literal id="Literal1" Text="Toggle User Menu" runat="server"/>
                </div>
            </div>
            <div id="header-holder">
                <div id="header">
                    <div id="main-navigation-login">
                        <asp:contentplaceholder id="mainnavigation" runat="server"/>
                    </div>
                </div>                    
            </div>
            <div id="content">
                
                <asp:contentplaceholder id="content" runat="server" />
                <div id="footer">
                    <asp:contentplaceholder id="footer" runat="server" />
                </div>
            </div>          
        </div>
   </form>
</body>
</html>
And the code behind file for this master page looks like.
using System;
using System.Web.UI;
using WebMarkupMin.WebForms.MasterPages;

namespace SitefinityWebApp.App_Data.Sitefinity.WebsiteTemplates.EC.App_Master
{
    public partial class main : MinifiedAndCompressedHtmlMasterPage
    {

        protected void Page_Init(object sender, EventArgs e)
        {
            this.Page.ViewStateUserKey =
            this.Page.User.Identity.IsAuthenticated ? this.Page.User.Identity.Name : "default";
        }
    }
}
I am going to try a few more experiments to try and get this working.
Coordinator
Mar 15, 2014 at 7:06 PM
Try to update WebMarkupMin to version 0.8.18.

From what type originally inherited the main class?
Mar 16, 2014 at 9:13 AM
Taritsyn wrote:
Try to update WebMarkupMin to version 0.8.18.

From what type originally inherited the main class?
I'll try the update later.

main inherits from MasterPage so I think it is fairly standard.
Mar 16, 2014 at 12:54 PM
Got it working with that update! Also had to modify to derive from MinifiedAndCompressedXhtmlMasterPage rather than MinifiedAndCompressedHtmlMasterPage. But solution compiles with either so the update has fixed something for me. Thanks!
Coordinator
Mar 16, 2014 at 3:44 PM
Excellent!

In this update all modules was explicitly compiled for one version of core. In addition, was a slightly increased performance of core.
Mar 17, 2014 at 12:10 PM
Good man! I appreciate your efforts.

I'll be testing this out over the coming months with Sitefinity in Hybid MVC/Webforms mode. I'll post any issues I encounter.

Is there a simple way to enable performance diagnostics? It would be nice whilst in Debug mode to know what savings are being made.

BTW I am in Ukraine are you in Ukraine or Russia?
Coordinator
Mar 17, 2014 at 1:33 PM
Edited Mar 17, 2014 at 1:33 PM
Is there a simple way to enable performance diagnostics?
You need to write and register your own logger (look the Info method and MinificationStatistics class).
It would be nice whilst in Debug mode to know what savings are being made.
I recommend to look the properties of webExtensions configuration section.

All these topics are described in the documentation. If you speak Russian, I recommend you to read my article «WebMarkupMin HTML Minifier – современный HTML-минимизатор для платформы .NET».
BTW I am in Ukraine are you in Ukraine or Russia?
I live in Russia.