Thoughts from the Wet Coast

The musings of an ASP.NET Developer from Canada's We(s)t Coast

Razor Tips and Tricks #2 - Razor’s Custom web.config File

Category: ASP.NET DotNetNuke
Last Modified: May 2 2017
Dec 9 2010

Yesterday we launched the Razor DotNetNuke Hackathon with a meeting of SEADUG (Seattle DotNetNuke User Group) held at Microsoft offices in beautiful downtown Bellevue.

For those of you proposing to write Razor “scripts” as part of the Hackathon, I have decided to write a series of short Tips and Tricks.

In this second post I will provide some information about the web.config file located in the RazorModules folder.

One of the neat features of Razor/WebPages is that the parser is highly configurable.  Its configuration is controlled by a new section in web.config (shown in Figure 1).  In theory the section can be placed in the web.config file in the web root, but as it is only of interest to Razor it can be placed in a custom web.config file in DesktopModules.

The file distributed with the Razor Host module is installed into the ~/DesktopModules/RazorModules folder.

Figure 1 – Custom web.config file


The entry on line 2 of the file tells the Razor parser that the Razor base type is DotNetNukeWebPage (not WebPage), and the namespaces nodes tell the parser to automatically “include” the specified namespaces.

If you want/need to use other namespaces – maybe from helpers that you wrote yourself – or that you found on the Internet - then adding the namespaces here means that you do not need “@using” statements in the .cshtml file(s).

By convention, the RazorHost module is installed in the RazorModules folder and as long as any other Razor module is located in a subfolder of RazorModules then it will “inherit” the settings in this custom web.config.

So, if you want to place your Razor script somewhere else – say DesktopModules/MyModules then you will need to deploy your own version of the web.config which contains the node at the least.


The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.