Meleze.web asp.net mvc 3 razor minify and compress html - asp.net

I have find meleze.web in nuget to remove extra white spaces in generated html result.
but when i set web.config new , and run nothing happend to result.
is there any correct sample or special configs ?
<configuration>
<system.web.webPages.razor>
<host factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory,Meleze.Web.Razor" />
</system.web.webPages.razor>
</configuration>

For a little bit of context, we're talking about the tool described here: http://cestdumeleze.net/blog/2011/minifying-the-html-with-asp-net-mvc-and-razor/
I used the following config:
<configuration>
...
<system.web.webPages.razor>
<host factoryType="Meleze.Web.Razor.MinifyHtmlWebRazorHostFactory, Meleze.Web, Version=1.0.0.1, Culture=neutral, PublicKeyToken=0a868b5321967eda" />
...

Maybe you have changed the /web.config instead of the /Views/web.config that config.
Contact the package owner if needed to get help ;-)

Related

ASP.NET URL Rewriting in very easy way

I want to know how to make SEF URL for web pages. After a little googling I have found many techniques, but all of them are so complicated. I do not need them. Is there any way to make SEF URL which is very easy to implement?
First download this reference .
Then import it to your web site.
under <configuration> node type this:
<configSections>
<section name="urlrewritingnet" requirePermission="false" type="UrlRewritingNet.Configuration.UrlRewriteSection, UrlRewritingNet.UrlRewriter"/>
</configSections>
The next step is typing the following code under <system.web> node:
the next one is putting the following line just before </configuration> tag:
<urlrewritingnet configSource="RewriteRules.config"/>
We are almost done!
Create a new .config file which matches the tag's configResource parameter. I preferred "RewriteRules.config".
Then it is time to create rewriting rules on RewriteRules.config file:
<urlrewritingnet rewriteOnlyVirtualUrls="true" contextItemsPrefix="QueryString" defaultPage="Default.aspx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07">
<rewrites>
<add name="DetailPageRule" virtualUrl="^~/VirtualDetailPageName/(.*)/(.*).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/RealDetailPage.aspx?param1=$1&param2=$2" ignoreCase=" true"/>
</rewrites>
</urlrewritingnet>
If you have more or less parameters you can change the count of (.)'s. Here there are only two parameters (param1 and param2), so there are only two (.) strings.
Final Step is giving links in according to the rules you have created.
It is simple and fast. But I do not know if there are drawbacks or any security issues.

Telerik namespace not found in deployed MVC3 application

I have just deployed a new MVC3 application, and after some efforts on my hosting provider's side, MVC3 seems to be running OK, but now I get the following compilation error before anything on the site loads:
CS0246: The type or namespace name 'Telerik' could not be found (are you missing a using directive or an assembly reference?)
This occurs in web.config on the following line:
<add namespace="Telerik.Web.Mvc.UI" />
I know the DLL is present in the bin folder on the host, so I'm a bit lost as to what else could be wrong.
If you are using Razor this line:
<add namespace="Telerik.Web.Mvc.UI" />
must occur in ~/Views/web.config and not in ~/web.config. Could this be your case?
Like this:
<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">
<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="Telerik.Web.Mvc.UI" />
</namespaces>
</pages>
</system.web.webPages.razor>
http://www.telerik.com/community/forums/aspnet-mvc/general/issue-with-telerik-mvc3-razor-content-appearing-at-the-top.aspx
Read the reply by Mike Kidder. Sorry for linking another forum, I know that's annoying but I'd rather give credit where due.
Two big takeaways when converting to Razor syntax:
1) Use #( .... ) when outputting html, not #{ .... ;}
- wrap the code for Telerik controls in parentheses, not brackets
- using brackets, you're essentially telling Razor to execute a method. You won't get any output
2) Remove the ".Render()" method for any Telerik controls. Not used in Razor.
You have to set Copy Local to true for the assemblies you have referenced. In your case expand References, select the assembly, press F4 to open the properties and set Copy Local to true. The assembly most probably is installed in the GAC so when you add a reference to it by default Copy Local is false.
it might be in the bin folder but, since you didn't mention this, did you actually add reference to the file in the project? after adding the reference to the dll, it should build correctly

Mapping classic asp pages to .net in IIS

I'm trying to map requests for classic asp pages to be handled by .net, so that it runs through a custom httpmodule.
In IIS I have remapped asp requests to aspnet_isapi.dll - I'm sure I've done this bit right
Now in my test app I am getting this error:
Server Error in '/TestASPRedirect' Application.
--------------------------------------------------------------------------------
This type of page is not served.
Description: The type of page you have requested is not served because it has been explicitly forbidden. The extension '.asp' may be incorrect. Please review the URL below and make sure that it is spelled correctly.
Requested URL: /testaspredirect/test.asp
Searching online for this error shows a load of people having problems with cassini, but this is not really relevant, I am testing this on both IIS 5.1 on XP dev machine, and have tested on IIS6 also getting the same error.
I have followed instructions for adding and registering a httphandler (see http://support.microsoft.com/default.aspx?scid=kb;en-us;Q308001), but I don't know what to put in the ProcessRequest routine to ensure the request gets passed on. What is the default .net httphandler, can I just map to this in web.config?: so something like:
<httpHandlers>
<add verb="*" path="*.asp" type="standard.nethttphandler"/>
</httpHandlers>
How do I tell asp.net that it needs to pass ASP requests on and not block?
Actually you are only one step far from the success. Adding following section to your Local website(or virtual directory) web.config file:
<configuration>
...
<system.web>
<compilation>
<buildProviders>
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>
<httpHandlers>
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="true"/>
</httpHandlers>
</system.web>
It looks like the .asp extension is mapped to the HttpForbiddenHandler.
If you're using ASP.NET 1.1 then open the following file:
C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG\machine.config
If you're using ASP.NET 2.0 then open this file:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\CONFIG\web.config
Search for "path="*.asp"", then comment out that line. It'll like something like:
<!-- machine.config/ASP.NET 1.1-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler"/>`
<!-- web.config/ASP.NET 2.0-->
<add path="*.asp" verb="*"
type="System.Web.HttpForbiddenHandler" validate="true"/>`
Locate the below file:
C:\WINDOWS\MICROSOFT.NET\FRAMEWORK\<FramworkVersion>\Config\web.config
where <FramworkVersion> is folder name:
open it in an XML editor .. (even notepad is fine)
and add below line :
<add path="*.asp" verb="*" type="System.Web.UI.PageHandlerFactory" validate="True"/>
under below XPath:
configuration/system.web/httpHandlers
replace the existing one!
Add below line:
<add extension=".asp" type="System.Web.Compilation.PageBuildProvider"/>
under below XPath:
/configuration/system.web/compilation/buildProviders
Worked like gem for me :)

Using ASPNet_Regiis to encrypt custom configuration section - can you do it?

I have a web application with a custom configuration section. That section contains information I'ld like to encrypt (was hoping to use ASPNet_RegIIS rather than do it myself).
Web.Config:
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="MyCustomSection"
type="MyNamespace.MyCustomSectionHandler, MyAssembly"/>
</configSections>
<configProtectedData>
<providers>
<clear />
<add name="DataProtectionConfigurationProvider"
type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL"
keyContainerName="MyKeyContainer"
useMachineContainer="true" />
</providers>
</configProtectedData>
<MyCustomSection>
<blah name="blah1">
<blahChild name="blah1Child1" />
</blah>
</MyCustomSection>
The configuration handler works great before trying to encrypt it. When I try to encrypt it with:
aspnet_regiis -pef "MyCustomSection"
c:\inetpub\wwwroot\MyWebsite -prov
DataProtectionConfigurationProvider
I get an error:
Encrypting configuration section... An
error occurred creating the
configuration section handler for
MyCustomSection: Could not load file
or assembly 'MyAssembly' or one of its
dependencies. The system cannot find
the file specified.
(c:\inetpub\wwwroot\MyWebsite\web.config
line 5)
I have tried with/without the provider configured. With/without section groups. With/Without having started the website before hand. I've tried temporarily putting my assembly in the GAC for the registration. I also tried my log4net section just to try something that wasn't mine, with no luck. I've run the command prompt as Administrator. Any ideas? Or can ASPNet_RegIIS just not be used for custom sections?
One final shot after viewing MSDN was changing my handler to inherit from ConfigurationSection rather than implementing IConfigurationSectionHandler since it was technically deprecated in 2.0 (hoping it was something regarding aspnet_regiis version). No luck there either.
Any ideas let me know. Thanks!
aspnet_regiis must be able to bind the assembly. The normal .net binding rules apply.
I get around this by creating directory called aspnet_regiis_bin in the same directory as aspnet_regiis.exe and an aspnet_regiis.exe.config file with aspnet_regiis_bin as a private path like this:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="aspnet_regiis_bin"/>
</assemblyBinding>
</runtime>
</configuration>
I then copy the assemblies that define the custom configuration sections into aspnet_regiis_bin so that aspnet_regiis can find them.
This procedure doesn't require the assemblies to be strong named or in the GAC but does require messing around in the framework directories.
I am using a workaround whereby I temporarly comment out the contents of the configSections element:
<configSection>
<!--
<section name="CustomSection" type="" />
-->
</configSection>
You can then run the encryption using aspnet_regiis -pef as usual. After this has run just uncomment the section and your site is ready to run.
This is a total hack, but I'm not sure that there's another way to do it without strongly naming the assembly that defines your custom section and GACifying it (although you mentioned that didn't work, either, and I'm not sure why it wouldn't). Since aspnet_regiis runs in the < drive >:\Windows\Microsoft.Net\Framework\< version > folder (in WinXP), you can copy the DLL that defines your config section into the relevant Framework\< version > folder, and then it should work.
For the record, I ended up with a little maintenance page to do this for me.
var currentConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
// Unprotect
ConfigurationSection section = currentConfig.GetSection("MyCustomSection");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
currentConfig.Save();
}
// Protect
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
currentConfig.Save();
}
Caveats: Your process will need write access to the config files being modified. You'll want some way to authorize who can run this. You'll generally restart the website when you Save.
The answer that is shown as correct is correct. I wanted to add a comment but could not because this is too long of a comment (sample config entries).
The section name should use the full name of the assemblies. A runtime assembly qualification does not work with aspnet_regiis.exe.
This WORKS:
<configSections>
<section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=9c844884b2afcb9e" />
</configSections>
But this DOESN'T WORK:
<configSections>
<section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security" />
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Security" fullName="Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=9c844884b2afcb9e" />
</assemblyBinding>
</runtime>

asp.net, url rewrite module and web.config

i'm using ASP.net with .NET 3.5 on IIS7 (Vista) with the URL Rewrite Module from Microsoft.
This means, that i have a
<system.webServer>
<rewrite>...</rewrite>
...
</system.webServer>
section within the web.config, but i get a warning, that within the system.webServer the element "rewrite" is not allowed.
How can i configure my system to allow (and maybe even have Intellisense) on the rewrite-part of the web.config?
Thank you
Christoph
I was able to get this working in Visual Studio 2010.
Start with Ruslan's post here and download the 2.0 IntelliSense file. Then, just follow the directions he posted previously here. All I ended up doing was running the following command as Ruslan instructs:
C:\download_directory\rewrite2_intellisense>cscript UpdateSchemaCache.js
As Christoph points out in his comment, make sure you replace VS90COMNTOOLS with VS100COMNTOOLS in UpdateSchemaCache.js before running the above command if you are using Visual Studio 2010.
I did not need to restart Visual Studio. I added the <rewrite> section only to the applicable Web.config transformation files, as having it in the main Web.config breaks local debugging.
I believe you need to have the URL Rewrite Module "installed" within the web.config file on your system.
You either need to install the module on your application via the IIS 7.0 interface or have your hosting firm do it for you.
I believe you need to define the module in your web.config like this:
<system.webServer>
<modules>
<add name="UrlRewriteModule" type="UrlRewritingNet.Web.UrlRewriteModule, UrlRewritingNet.UrlRewriter" />
</modules>
</system.webServer>
Update: Intellisense can be setup here:
http://ruslany.net/2009/08/visual-studio-xml-intellisense-for-url-rewrite-1-1/
Update: Verify that the sectionGroup is identified in %systemroot%\system32\inetsrv\config\applicationHost.config:
<sectionGroup name="rewrite">
<section name="rules" overrideModeDefault="Allow" />
<section name="globalRules" overrideModeDefault="Deny" allowDefinition="AppHostOnly" />
<section name="rewriteMaps" overrideModeDefault="Allow" />
</sectionGroup>

Resources