Sharing code behind files

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DaveRook
    New Member
    • Jul 2007
    • 147

    Sharing code behind files

    Hello

    I have a website which sells 200 products. Currently I use a results.aspx page to display and the querystring tells the databas which prodcut to show!

    However, not so good for Google (IMO). So, I want to create 200 pages, each page called the same as the product name.

    So, it was once results.aspx?s= batman and results.aspx?s= batman2
    It will now been seen as batman.aspx and batman2.aspx

    I want to share the code behind file with all 200 pages so I don't have to re-write everything each time an update is required. The code behind will use a Request.ServerV ariables["URL"] to work out the page name which will then be used to query the databases.

    My question is: is this bad practice? My concern is too many resources requiring this one page will slow the site/server down too much! Don't get me wrong, this only has 4000 - 5000 visitors per month (it's not Amazon) but I still want best practices!

    Any suggestions

    Thank you

    Dave
  • DaveRook
    New Member
    • Jul 2007
    • 147

    #2
    To further above and to simplify

    Why use a URL rewriter when I can just reference many aspx pages to one CodeFile?

    Thanks

    Dave

    Comment

    • Curtis Rutland
      Recognized Expert Specialist
      • Apr 2008
      • 3264

      #3
      This is what URL rewriting is designed for. Basically, you need one page, but for SEO purposes you want it to appear to have several pages. Blogs do this, stores do this, most data-driven sites do this.

      The best practice is NOT to create hundreds of ASPX pages that use the same .CS file. That's a maintenance nightmare. Any time you change a name, you have to hunt that file down in the directory structure, and make changes there. You have to have physical access to the filesystem. Or say you need to make a change? You'd have to open up 200 pages and make the changes.

      If you use rewriting (which I am not even close to an expert on, hopefully someone else would be able to help you set that up) you can avoid all that and have your site entirely driven from the database. One page, one codebehind, one datasource. Easy maintenance.

      Comment

      • DaveRook
        New Member
        • Jul 2007
        • 147

        #4
        Hello

        Thank you InsertAlias, I have already started to look into Url rewriting. I just want to know why this method doesn't work!

        In my case, I am using a datareader and 1 label on the page. So, my code behind page looks like

        Read from SQL
        New DataReader
        While read()

        lbText.Text = "text 1";
        lbText.Text +="text 2";

        etc

        So all maintenance is actually done on just one page (the code behind page).

        If the code behind was not designed for this, why do we have an option to choose which code behind page to use with the codefile attribute? Any ideas?

        Thank you

        Dave

        Comment

        • Curtis Rutland
          Recognized Expert Specialist
          • Apr 2008
          • 3264

          #5
          why do we have an option to choose which code behind page to use with the codefile attribute?
          That's there to tell the compiler the file location of where its code is located. It's not to allow multiple pages to use single codefiles. While what you are suggesting is technically possible, that's not the intended use, and indeed isn't the most efficient way of doing things by far.

          As to maintenance, what if you need to add a second label to the page? Even if you never had to make a change, you'd still need to generate a physical file every time you add a new product, and you'd still need to delete or remove a file when you remove one. And rename one if you change it.

          With a data-driven system and re-writing, you can control your content from a web interface (if you design one), never having to change physical files.

          Trust me. If you do this right, maintenance will be a snap, and you'll be glad you did it the right way. Trying to maintain 200 redundant files will be a mess.

          Comment

          • DaveRook
            New Member
            • Jul 2007
            • 147

            #6
            insertAlias

            Thank you for such a good clear answer! Just to know that it is possible but wrong has helped me a huge amount - and to understand that it is about the maintanence more than the resources is really important as well.

            Thank you, I guess I was re-inventing the wheel! Url rewrite, here I come!!

            Thank you

            Dave

            Comment

            Working...