I'm using the Meleze.Web library for my web application and I want to add the compression only on release builds.
I tried to do a web.config transformation but in the Web.Release.config file, when I try to do
<configuration>
<system.web.webPages.razor>
<host xdt:Transform="Replace" factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory, Meleze.Web, Version=1.4.0.3, Culture=neutral, PublicKeyToken=0a868b5321967eda" />
</system.web.webPages.razor>
</configuration>
gives me an error saying that the :Transform is not declared. Any help would be appreciated. Please note, this is the Web.Config in the Views folder.
You can use the following Web.Release.config file for transforming your Web.config file.
<?xml version="1.0" encoding="utf-8"?>
<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an attribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web.webPages.razor>
<host factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory, Meleze.Web, Version=1.4.0.6, Culture=neutral, PublicKeyToken=0a868b5321967eda" xdt:Transform="Replace" />
</system.web.webPages.razor>
<system.web>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
</configuration>
For me, its working perfectly. Steps that I followed are here:
Install Meleze.Web via Package Manager Console PM> Install-Package Meleze.Web
Open View/Web.config and replace the <host...../> line inside <system.web.webPages.razor> with <host factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory, Meleze.Web, Version=1.4.0.3, Culture=neutral, PublicKeyToken=0a868b5321967eda" />
That's all I did. Btw, I am using MVC 4.
Related
I am currently working on an MVC project. The project is working fine on another colleagues machine but I am having trouble with this project. It constantly gives errors with Html helper classes.
"System.Web.WebPages.HtmlHelper does not contain a definition for 'TextboxFor' does not contain definition and no extension method 'TextBoxFor' accepting argument of type System.Web.WebPages.HtmlHelper could be found."
I have googled this problem but have not found any useful solution.
Here are some steps that I tried to solve this problem.
Clean solution and rebuild it.
removed bin and obj folder and rebuild the solution.
checked references in web.config files (both)
Added refrences in web.config like System.Web.Mvc etc..
Copied packages from other colleagues' machine.
Note: I am using visual studio 2013 with MVC 5
Sounds like you're missing the following in the Web.Config in the views folder:
/Views/Web.Config
<?xml version="1.0"?>
<configuration>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage"> // <-- this line and contents are important
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
</namespaces>
</pages>
</system.web.webPages.razor>
Views typically derive from System.Web.Mvc.WebViewPage which is configured in the web.config. Make sure the version above matches the version you need.
I having this error but I cant find the way to help it
Server Error in '/' Application.
Configuration Error
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.
Parser Error Message: 'System.Web.Mvc.WebViewPage' is not allowed here because it does not extend class 'System.Web.UI.Page'.
Source Error:
<add name="ApplicationInsightsWebTracking"
type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule,
Microsoft.AI.Web" />
</httpModules>
**<pages pageBaseType="System.Web.Mvc.WebViewPage">**
<namespaces>
<add namespace="GridMvc" />
Source File: C:\app\web.config Line: 32
It is clear that System.Web.Mvc.WebViewPage namespace added at the wrong place (as shown by httpModules used before the line causing problem). The correct place to add respective namespace is in a web.config file inside Views folder under system.web.webPages.razor element, as shown below:
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Routing" />
<add namespace="GridMvc" />
<!-- other namespaces -->
</namespaces>
</pages>
</system.web.webPages.razor>
The pages element under system.web is primarily intended for webforms project configuration (under System.Web.UI.Page namespace), which often contains 2 attributes (validateRequest & clientIDMode):
<pages validateRequest="true" clientIDMode="AutoID">
To use MVC version of pageBaseType attribute, you need to check if current pages element exists inside system.web.webPages.razor. In this case you added the namespace incorrectly under system.web, which doesn't inherit System.Web.Mvc namespace & throwing disallowed namespace error.
I am using VS2012 and having some troubles publishing an mvc4 website.
None of my release settings are applied.
Within my configs I have this
Web.Config
<compilation debug="true" targetFramework="4.0" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login" timeout="2880" name="***" enableCrossAppRedirects="true" />
Release
<?xml version="1.0"?>
<!-- For more information on using Web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="ApiBaseUrl" value="https://api.mydomain.com/api/" xdt:Transform="Replace" xdt:Locator="Match(key)" />
</appSettings>
<!--
In the example below, the "SetAttributes" transform will change the value of
"connectionString" to use "ReleaseSQLServer" only when the "Match" locator
finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
-->
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
<authentication mode="Forms" xdt:Transform="Replace">
<forms loginUrl="~/Account/Login" timeout="2880" name="***" enableCrossAppRedirects="true" domain="www.mydomain.com"/>
</authentication>
<!--
In the example below, the "Replace" transform will replace the entire
<customErrors> section of your Web.config file.
Note that because there is only one customErrors section under the
<system.web> node, there is no need to use the "xdt:Locator" attribute.
<customErrors defaultRedirect="GenericError.htm"
mode="RemoteOnly" xdt:Transform="Replace">
<error statusCode="500" redirect="InternalError.htm"/>
</customErrors>
-->
</system.web>
<system.net>
<mailSettings>
<smtp xdt:Transform="Replace">
<network host="localhost"/>
</smtp>
</mailSettings>
</system.net>
<dotless xdt:Transform="Replace" minifyCss="true" cache="true" web="false" />
</configuration>
I am publishing when set to Release.
Can anyone see anything wrong I am doing?
If your web.config includes location tags, you need to make sure those are accounted for in the Release config as well.
Check your Publish Profiles in the Web Publishing Wizard. In VS2010, the web.config transforms were applied according to the build configuration selected at the time of publish, but with the new Web Publishing Wizard I believe it's stored right inside of the Publish Profile. Which I believe is the one they included with VS2012
i'm trying to use the Web.config transformations in my ASP.NET MVC 2 project running on .NET 4. However, I am having a problem:
// Root Web.config
<add name="MyDB" connectionString="default...default" />
// Root Web.Debug.config
<add name="MyDB" connectionString="debug...debug" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
// Root Web.Release.config
<add name="MyDB" connectionString="release... release" xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
I keep getting this error:
Warning No element in the source document matches '/configuration/add[#name='MyDB']' C:\filePath\Web.Release.config
I narrowed this down to the Web.Config file inside the Views folder. If I give it a connectionString, such as the one in the root Web.config file, than all is well, but that means I have to maintain two Web.config files. Is there any solution to this? Am I doing something wrong?
Not sure why web.config in the views folder is being implicated but from the error you're getting it sounds like you've got a mismatch between the element in web.config and the transform config files.
In web.config, assuming <add /> is a child of <connectionStrings /> you'd do:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...
<connectionStrings>
<add name="SomeName" providerName="System.Data.SqlClient" connectionString="SomeConnectionString" />
</connectionStrings>
...
</configuration>
and in web.debug.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
...
<connectionStrings>
<add xdt:Locator="Match(name)" xdt:Transform="SetAttributes(connectionString)" name="SomeName" connectionString="SomeOtherConnectionString" />
</connectionStrings>
...
</configuration>
As I already said:
Don't forget to manually copy all the other attributes of "configuration" from the original "web.config", as it seems that VS2012 doesn't do it automatically, so there will be no match...
I'm trying to add a section to an ASP.NET web.config file for using the default profile provider. Here's what I'm adding to web.config in the system.web node:
<profile defaultProvider="AspNetSqlProfileProvider">
<providers>
<clear/>
<add name="AspNetSqlProfileProvider"
type="System.Web.Profile.SqlProfileProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="ApplicationServices"
applicationName="/"
/>
</providers>
<properties>
<group name="UserDetails">
<add name="FirstName" />
<add name="LastName" />
<add name="BirthDate"
type="System.DateTime" />
</group>
</properties>
</profile>
I can build the website successfully, but as soon as it completes I get the prompt that web.config has been modified outside of the editor and do I want to reload it. I click Yes, and the profile section disappears. Everything else in the web.config file remains intact and functioning correctly.
Any ideas of where to look for troubleshooting this issue? Thanks!
It sounds like you are editing the output config file in the Web site's root and that the build is overwriting with the unedited config held in the ASP.NET project.