Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In a nutshell don't do this in your <code>Global.asax</code>. Use the IIS7 Url Rewriter instead:</p> <blockquote> <p><a href="http://learn.iis.net/page.aspx/460/using-the-url-rewrite-module/" rel="nofollow">Using the URL Rewrite Module</a></p> </blockquote> <p>You have one of two solutions -</p> <ol> <li><p>Use a <a href="http://learn.iis.net/page.aspx/469/using-rewrite-maps-in-url-rewrite-module/" rel="nofollow">URL Rewrite Map</a> and map every category name to a category ID:</p> <pre><code>&lt;rewrite&gt; &lt;rewriteMaps&gt; &lt;rewriteMap name="StaticRewrites"&gt; &lt;add key="/products/category/electronics" value="/products.aspx?category=45" /&gt; &lt;add key="/products/category/books" value="/products.aspx?category=46" /&gt; &lt;add key="/products/category/dvds" value="/products.aspx?category=47" /&gt; &lt;/rewriteMap&gt; &lt;/rewriteMaps&gt; &lt;rules&gt; &lt;rule name="Rewrite Rule 1 for StaticRewrites" stopProcessing="true"&gt; &lt;match url=".*" /&gt; &lt;conditions&gt; &lt;add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" /&gt; &lt;/conditions&gt; &lt;action type="Rewrite" url="{C:1}" appendQueryString="False"/&gt; &lt;/rule&gt; &lt;/rules&gt; &lt;/rewrite&gt; </code></pre></li> <li><p>Use a more "dynamic" rewrite:</p> <pre><code>&lt;rewrite&gt; &lt;rules&gt; &lt;rule name="RedirectUserFriendlyURL1" stopProcessing="true"&gt; &lt;match url="^products\.aspx$" /&gt; &lt;conditions&gt; &lt;add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" /&gt; &lt;add input="{QUERY_STRING}" pattern="^([^=&amp;amp;]+)=([^=&amp;amp;]+)$" /&gt; &lt;/conditions&gt; &lt;action type="Redirect" url="products/{C:1}/{C:2}" appendQueryString="false" /&gt; &lt;/rule&gt; &lt;rule name="RewriteUserFriendlyURL1" stopProcessing="true"&gt; &lt;match url="^products/([^/]+)/([^/]+)/?$" /&gt; &lt;conditions&gt; &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /&gt; &lt;add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /&gt; &lt;/conditions&gt; &lt;action type="Rewrite" url="products.aspx?{R:1}={R:2}" /&gt; &lt;/rule&gt; &lt;/rules&gt; &lt;/rewrite&gt; </code></pre> <p>In the above case you'd need to change your <code>products.aspx</code> page to accept the category name, then in that page look up the actual integer ID of the category in the database.</p></li> </ol> <p>Passing the rewrite responsibility to IIS7's URL Rewrite module (or any other rewriter such as Iconics IIRF or HeliconTech's ISAPI Rewrite) means that you can change these rules separately rather than burning them into your code. Burning these rules into your code means you have to redeploy every time you make a change.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload