The following must be added into your web.config:

	<sectionGroup name="dnAide">
		<section name="web" type="DNAide.Configuration.WebConfig" allowDefinition="MachineToApplication" restartOnExternalChanges="true"/>

Then add the dnAide configuration section:

<!-- dnAide -->
<!-- /dnAide -->

Then add the httpModule

		<add type="DNAide.Web.UrlRewriter" name="UrlRewriter"/>

Common urlRewriter configuration options

  • firesOnEvent: "BeginRequest, AuthorizeRequest, AuthenticateRequest, None". Default "BeginRequest"
  • virtualUrlsOnly: Rewriting will only occur for virtual file requests, i.e. the file does not physically exist on the server. Default "True"
  • applicableFileExtensions: Valid file extensions for rewriting to occur. Default ".asp,.htm". To allow all, use ".*"
  • defaultPage: If the requested Url does not include a file name i.e. http://www.mywebsite.com/news, this page will be appended by the rewriter to the url e.g. http://www.mywebsite.com/news/index.aspx

  • moveViewState: The rewriter can be used to move the ViewState to the bottom of the form. Useful for SEO.


Please note. You do not have to define your rules in the web.config. If you use a SiteMap, there are a couple of extra attibutes you can use which are linked to the UrlRewriter. See DNAideXmlSiteMapProvider for more info.

Configuring Rules

	<!-- Simple rule -->
	<add id="rule-1" matchExpression="~/news/(.*)/(.*).aspx" destination="~/_Templates/WebForms/ViewNews.aspx" />

	<add id="rule-2" matchExpression="~/products/(.*)/(.*).aspx" destination="~/_Templates/WebForms/ViewProduct.aspx?id=$2" />

	<!-- Ignore rule -->
	<add id="ignore-rule-1" matchExpression="~/_Templates/(.*)" destinationType="Ignore"/>

Common urlRewriter rule options

  • matchExpression: Regular expression used against requested Url
  • destination: Where the request should be redirected to
  • destinationType: "UrlPattern, SiteMapNodeKey, Ignore". Default "UrlPattern". "SiteMapNodeKey" will rewrite the request if a pattern is matched to a node in the sitemap
  • ruleType: "Rewrite, Redirect". Default "Rewrite".
  • redirectStatusCode: i.e. what is added to the response header e.g. 301, 404 etc. Default = "301"

Last edited Mar 10, 2007 at 11:52 AM by stebrennan, version 6


No comments yet.