Tech Off Thread

11 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

url rewriting for cms solution

Back to Forum: Tech Off
  • User profile image
    davidvl

    Hello all,

    I have written a simple content management solution in ASP.NET , which results in URL's like viewer.aspx?id=12. I would like to handle virtual paths like mydomain.com/productx though, that will be redirected to a CMS URL without the browser knowing it.

    I have read an article on:
    http://www.dotnet247.com/247reference/msgs/11/59939.aspx

    And it seems to be possible only through:
    - making IIS handle every request (also without extension or .html etc.) by ASP.NET, which is not possible since I'm on shared hosting
    - Creating a 404 handler that will handle all nonphysical requests.

    This last solution results in 404 errors in the log files though, which is not what I want. Why is this so hard? Any suggestions?

    Thank you in advance.

    Kind regards,

    David van Leerdam

  • User profile image
    Maurits

    You could set up a directory /productx/ with a default.aspx document that redirects to /viewer.aspx?productid=12

  • User profile image
    W3bbo

    Or set up 404 handling for only ASPX files.

    So website.com/products/Foo.aspx and website.com/staff/Bar.aspx are rewritten to website.com/products.aspx?product=Foo, webdevil.com/staff.aspx?staff=Bar

    ...or install a URL Rewriting ISAPI?

  • User profile image
    davidvl

     Hi Maurits and W3bbo,

    Thanks for your replies.

    My problem is that these paths are dynamically created. So they exist in a database , but are not physical there. Like the 'productx' does not exist.

    That's why I need to catch this early in the request stack, and rewrite the URL to a physical URL that this virtual path is linked to.

    Doing it with a 404 handler is not an option, since this would log all requests coming from my handler as an 404 error.
    The ISAPI extension would normally be a nice solution indeed. The application is hosted on a shared hosting service though. So I can't install such an extension.

    Any other suggestions or possible solutions?

    Thanks very much in advance.

    kind regards,

    David van Leerdam

  • User profile image
    Maurits

    davidvl wrote:
    My problem is that these paths are dynamically created. So they exist in a database , but are not physical there. Like the 'productx' does not exist.


    How do entries get added to the database?  Could you programmatically create the directories and their default.aspx redirection pages at insert time?

  • User profile image
    davidvl

    Hey Maurits,

    I could do that indeed. Problem is that I'd like to keep my physical directory as clean as possible. I.e. having 'virtual paths' 'or content aliases' created by the content manager being real 'virtual' and not physical paths which might create a big mess of folders.

    But as I understand there are no nice solutions to this.
    Is this changed in ASP.NET 2.0?

    Kind regards,

    David van Leerdam

  • User profile image
    Harlequin

    You can use, I belive, an HttpHandler. This is what we use in a few places and I know Microsoft uses them extensively. Every time you see a page on the Microsoft site with the .mspx extention, that file doesn't actually exist. It simply responses out the appropriate template and grabs the content from special Xml files.

  • User profile image
    sbc

    The problem with IIS is that it handles requests based on extension, so HttpHandlers will only work with files whose extensions are used by ASP.NET.

    So http://site.com/foo/ would return 404. http://site.com/foo/default.aspx can be handled, but you end up with URL's you may not want.

    Hopefully IIS7 will be more like Apache - where web.config files work like .htaccess files and you can add your own file types without needing to go into IIS. If it is not fixed by then I would be surprised and extremely disappointed. If a free web server can do this (and has done it for years), why can't IIS - which was paid for through the Windows license?

    404 is often used as it can handle any file types (as long as your host has set /404.aspx as your error page - I'm sure even if they haven't, they would change it for you).

    Until you can configure your site without needing IIS, the only thing that will work is the 404 error page.

  • User profile image
    Maurits

    davidvl wrote:
    Problem is that I'd like to keep my physical directory as clean as possible.


    Why?

  • User profile image
    dotnetjunkie

    davidvl wrote:

    Doing it with a 404 handler is not an option, since this would log all requests coming from my handler as an 404 error.



    NO!  That's the beauty of it, it does not log as a 404! (or any error!)  TRY IT!

    I thought this too beofre I had tried it.

  • User profile image
    zhuo

    Maurits wrote:
    davidvl wrote: Problem is that I'd like to keep my physical directory as clean as possible.


    Why?


    I concur!

    A lot of content management system out there do indeed implement what you've described by generating static html files. This is good for both SEO reasons as well handling large amount of traffic.


    James Big Smile

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.