Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 11 of 11

Thread: Urlrewrites

  1. #1
    Rex is offline Banned
    Join Date
    Nov 2007
    Posts
    561

    Default Urlrewrites

    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

  2. #2
    ASPDNSF Staff - Buddy is offline Banned
    Join Date
    Jul 2005
    Posts
    378

    Default

    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.

  3. #3
    Rex is offline Banned
    Join Date
    Nov 2007
    Posts
    561

    Default

    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.

  4. #4
    devariojay is offline Junior Member
    Join Date
    Sep 2008
    Posts
    1

    Default url rewrites

    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?

  5. #5
    Jesse is offline Banned
    Join Date
    May 2008
    Posts
    1,329

    Default

    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.

  6. #6
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    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

  7. #7
    Rex is offline Banned
    Join Date
    Nov 2007
    Posts
    561

    Default

    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.

  8. #8
    BFG 9000 is offline Senior Member
    Join Date
    Oct 2006
    Location
    South UK
    Posts
    882

    Default

    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

  9. #9
    ASPDNSF Staff - Jon's Avatar
    ASPDNSF Staff - Jon is offline Senior Member
    Join Date
    Sep 2004
    Posts
    11,419

    Default

    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

  10. #10
    ASPDNSF Staff - Buddy is offline Banned
    Join Date
    Jul 2005
    Posts
    378

    Default

    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.

  11. #11
    Rex is offline Banned
    Join Date
    Nov 2007
    Posts
    561

    Default

    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.