Those of you who may be using a lot of rewrites, the default cache size for the RegEx compiled expressions is 50. Set it to an optimal level for your use.
System.Text.RegularExpressions.RegEx.CacheSize
Those of you who may be using a lot of rewrites, the default cache size for the RegEx compiled expressions is 50. Set it to an optimal level for your use.
System.Text.RegularExpressions.RegEx.CacheSize
To clarify, the .NET default cache size is 15 we set it to 50.
Last edited by Rob; 04-08-2008 at 10:06 PM.
Thank you for that correction.
Just wanted to add, for those who need a more complex rewrite scheme, say to emulate the Apache mod_rewrite rules-style, you can create a XML Package to run in the BeginRequest event and make a recipe for anything your heart desires. Mine works very very nicely
XmlPackage2 uw = new XmlPackage2("urlrewrite");
uw.TransformString();
HttpContext.Current.RewritePath(uw.FinalResult);
return false; //now run ASPDNSF rules
Last edited by Rex; 04-09-2008 at 05:16 PM.
Hi, if I wanted to merge all my url rewrites from a http.conf file into this system, how would I go about doing that?
Also, if it requires making an XML package like your post suggests, how would I go about doing that in the CP?
It's not something you can do in the control panel. It's something you set in the web.config which may be as easy as a cut and paste of what you currently have, all the way into loading them as Rex says using an XMLPackage. It would most likely be easier to add your rewrites to the config file.
Hi All,
This seems like the right place to ask this......
What's the easiest way for me to create a marketing friendly url?
e.g. let's say I'm having a flyer printed to promote my great range of widgets, I'd like to have the url http://www.mysite.com/widgets
A few restrictions.....
I have no access to IIS
I have in the past created a directory in the root (called widgets in this case) & included a default.aspx file which does a meta refresh to the correct destination e.g. c-123-widgets.aspx, however, because of the set-up here, I have to recreate every time we upgrade the site.
I guess ideally, it would be easily maintainable - a txt, csv, xml document which contains all of the mappings...... or is it better to add to the web.config?
Also ideally, I guess a 301 redirect is better than a meta refresh.......
TTFN
BFG
Do the same thing as the rewrite already mentioned. Except you perform a 301 Response.Redirect instead of a HttpContext.RewritePath
Or skip the XML Package altogether and just code the redirect based on the Request.Url string that you want to identify and redirect.
Thanks Rex - I'm still struggling though - I can't even get this to work in the web.config :-
<rule url="/test" rewrite="/showproduct.aspx?ProductID=123" />
The above just gives me a 404 when I navigate to www.domain.com/test
Any ideas/pointers?
TTFN
BFG
You'll need to add a "wildcard application mapping" to IIS. The problem is that extension-less URLs aren't automatically routed to ASP.NET by IIS v6 or IIS v7 (in classic pipeline mode).
IIS uses the extension to decide who handles what request, and the wildcard application mapping would force everything to be handled by ASP.NET.
Jon Wolthuis
Create a custom 404 handler and put some logic in it to redirect to the page you want the customer to see. You could create a table to store the mappings. If you didn't want the url in the browser to change to a page (i.e. you wanted to stay at http://www.mysite.com/widgets) then just have your 404 page return the appropriate content. If your page is just an XmlPackage then your table could just map an incoming URL to an XmlPackage that your 404 page runs.
BFG,
That rewrite should work.
I tested it. It works perfectly.
I cannot guess what you are doing incorrectly.
Most requests within a web application should pass through the Application's BeginRequest logic to give the application a chance to redirect or process the request in a fashion it deems fit.
The only thing I can think of is you already have another handler of some sort usurping the rewrite rule.
Check your web.config for other handlers of "/test" paths - do a search for "/test".
Last edited by Rex; 10-08-2008 at 11:10 PM.