How to rewrite urls without having access to IIS MMC

Discussion in 'ASP .Net' started by Max2006, Nov 6, 2006.

  1. Max2006

    Max2006 Guest

    Max2006, Nov 6, 2006
    1. Advertisements

  2. Max2006

    philwilks Guest

    Hi Max,

    Unless I'm mistaken, I don't think it's going to be possible to do this
    exactly as you want. The main problem is that files with extensions
    like .jpeg or .gif are not handled by the ASP.Net engine. In other
    words, the ASP.Net part of the server won't have any idea that a
    request for one of these pages has been made.

    If you had your own server, you could change this behavior and have
    requests for .jpeg files handled by ASP.Net. However, I seriously doubt
    that your hosting provider would be willing to set this up.

    The next best option is to use a "custom HTTP handler", which is a
    special ASP.Net page with the extension .ashx. In fact, your
    ImageHandler.aspx page should really be a .ashx page, but you'll
    probably get away with doing it either way.

    I highly recommend using to do the re-writing.
    ASP.Net 2.0 does allow you to do some basic re-writing, but it doesn't
    let you use regular expressions or wildcards so you'd have to write a
    separate rule for every single image file. Once you've downloaded
    UrlRewritingNet, you'll be able to re-write URLs with a certain "shape"
    just as you want.

    However, what you MUST remember is that you can't re-write .jpeg files
    without getting access to the IIS MMC. Instead, you'll need to re-write
    files that match "/blah.ashx" to "/images/ImageHandler.ashx?n=blah". In
    your web.config, this means having something like this for the
    UrlRewritingNet configuration...

    <urlrewritingnet rewriteOnlyVirtualUrls="true" compileRegex="true"
    xmlns="" >
    <add virtualUrl="^~/(.*).ashx"
    destinationUrl="~/images/ImageHandler.ashx?n=$1" />

    I hope this helps! Once you get it working it's great.

    philwilks, Nov 6, 2006
    1. Advertisements

  3. Hi Max,

    I'm afraid that's not possible to rewrite a path ended with an extension
    that is not mapped to ASP.NET engine in IIS. If you take a look at an
    ASP.NET web site's "Application Settings" in its IIS property page (click
    on "Configuration" button to see the Application Mappings), you will see
    extensions such as .aspx, .config are mapped to use aspnet_isapi.dll. For
    extensions are not mapped, IIS will serve them directly. Since you're
    asking how to rewrite the path of a .jpeg file, which is normally not
    mapped, I think it cannot be done.

    For extensions do mapped to ASP.NET, you can find a URL rewriter
    implementation here:

    #URL Rewriting with ASP.NET - The Code Project - ASP.NET
    Demonstrates the use of regular expression-based URL Rewriting, similar to
    mod_rewrite with ASP.NET

    Walter Wang (, remove 'online.')
    Microsoft Online Community Support

    Get notification to my posts through email? Please refer to
    ications. If you are using Outlook Express, please make sure you clear the
    check box "Tools/Options/Read: Get 300 headers at a time" to see your reply

    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Walter Wang [MSFT], Nov 6, 2006
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.