locked
creating a simple backend without a database? RRS feed

  • Question

  • User1322403867 posted

    Hey,

     

    I want to start creating sites with simple backends! I don't know much about databases though and I don't want to jump straight into creating sites with databases anyway. So I want to find out what the best way of creating a simple backend without using a database is.

    So here is the scenario..  I have an asp.net webpage which is a prices page detailing the prices of services at a hair salon. The prices change every 6 months so I want to give the client a simple backend so he can update the prices himself. The backend will just be a table of inputs populated with the current prices which can be changed and then click 'save changes' to update the site.

    Now what is the best way of implementing this? 

    A)    In the prices page, hard code an html table, within each cell code a <span> tag with an id for the price that will go within the span tag like id="menscut" and within the span tag hard code the price of the service. Then wirte a C# class called 'edit' that is used when the 'save changes' button is clicked on the backend page. When 'save changes' is clicked the 'edit' class parses the prices.aspx page and finds <span id="menscut">£20</span>  and then changes it to <span id="menscut">£22</span> (or what ever new price has been entered in the backend) and then saves the new edited prices.aspx page over the old one on the server.

    or

    B)    Don't hard code prices into the prices.aspx but instead store the prices in a seperate .txt or .xml file. Every time the prices.aspx page loads it runs a class called 'populate' which extracts the prices from the .txt file or .xml file and inserts them into the table in the prices.aspx page. And now the edit class instead of editing the prices.aspx page it edits the .txt or .xml file.

     

    So which of those ways is better, or if they are fairly even pegged what are the pros and cons of each?

    Or are there any other options I haven't thought of?

     

    Thanks,

     

     

    Thursday, February 11, 2010 2:17 PM

Answers

  • User-952121411 posted

    B)    Don't hard code prices into the prices.aspx but instead store the prices in a separate .txt or .xml file. Every time the prices.aspx page loads it runs a class called 'populate' which extracts the prices from the .txt file or .xml file and inserts them into the table in the prices.aspx page. And now the edit class instead of editing the prices.aspx page it edits the .txt or .xml file.
     

    Of the (2) options you provided #2 is by far the better choice.  Hardcoding dynamically changing values is a bad idea and often requires more work that centralizing those values in the 1st place.  If you don't want to use a database, then a file that sits aside an application to store the values is the next option.  The type of file you select is up to you; each have their advantages.  The nice thing about an XML file is you have the ability to use LINQ to XML to query the data out of the file, or just use basic XML class methods to extract the data.  The point is you have options.

    Another consideration is the web.config file.  This is already deployed with the application and can be accessed easily.  My recommendation in using the <appSettings> section of the web.config: only use this method if the values you need to place in it few and simple.  If you begin to need a structure beyond simple key/value pairs then the web.config is not a good place.  I recommend this because you were talking about set prices for haircuts.  If you just have a few straightforward values, then the web.config could be a good option.  Another really nice feature of the web.config file is that is can have its <appSettings> section encrypted (with aspnet_regiis.exe tool), so that nobody on the server could see your prices, if this was of concern.

    Below are a few links that may help you with the above suggestions:

    How to: Read Application Settings from the Web.config File:

    http://msdn.microsoft.com/en-us/library/610xe886.aspx

    Accessing the appSettings Section:

    http://msdn.microsoft.com/en-us/library/aa735785(VS.71).aspx

    <appSettings> Element:

    http://msdn.microsoft.com/en-us/library/aa903313(VS.71).aspx

    How to read XML from a file by using Visual C#:

    http://support.microsoft.com/kb/307548

    XML in .NET: .NET Framework XML Classes:

    http://msdn.microsoft.com/en-us/magazine/cc302158.aspx

    Navigating XML Files in .NET:

    http://www.devsource.com/c/a/Architecture/Navigating-XML-Files-in-NET/1/

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 12, 2010 12:02 PM

All replies

  • User-1823825456 posted

    give a try with the xml file to keep ur data.

    Thursday, February 11, 2010 11:11 PM
  • User-952121411 posted

    B)    Don't hard code prices into the prices.aspx but instead store the prices in a separate .txt or .xml file. Every time the prices.aspx page loads it runs a class called 'populate' which extracts the prices from the .txt file or .xml file and inserts them into the table in the prices.aspx page. And now the edit class instead of editing the prices.aspx page it edits the .txt or .xml file.
     

    Of the (2) options you provided #2 is by far the better choice.  Hardcoding dynamically changing values is a bad idea and often requires more work that centralizing those values in the 1st place.  If you don't want to use a database, then a file that sits aside an application to store the values is the next option.  The type of file you select is up to you; each have their advantages.  The nice thing about an XML file is you have the ability to use LINQ to XML to query the data out of the file, or just use basic XML class methods to extract the data.  The point is you have options.

    Another consideration is the web.config file.  This is already deployed with the application and can be accessed easily.  My recommendation in using the <appSettings> section of the web.config: only use this method if the values you need to place in it few and simple.  If you begin to need a structure beyond simple key/value pairs then the web.config is not a good place.  I recommend this because you were talking about set prices for haircuts.  If you just have a few straightforward values, then the web.config could be a good option.  Another really nice feature of the web.config file is that is can have its <appSettings> section encrypted (with aspnet_regiis.exe tool), so that nobody on the server could see your prices, if this was of concern.

    Below are a few links that may help you with the above suggestions:

    How to: Read Application Settings from the Web.config File:

    http://msdn.microsoft.com/en-us/library/610xe886.aspx

    Accessing the appSettings Section:

    http://msdn.microsoft.com/en-us/library/aa735785(VS.71).aspx

    <appSettings> Element:

    http://msdn.microsoft.com/en-us/library/aa903313(VS.71).aspx

    How to read XML from a file by using Visual C#:

    http://support.microsoft.com/kb/307548

    XML in .NET: .NET Framework XML Classes:

    http://msdn.microsoft.com/en-us/magazine/cc302158.aspx

    Navigating XML Files in .NET:

    http://www.devsource.com/c/a/Architecture/Navigating-XML-Files-in-NET/1/

    Hope this helps! Smile

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 12, 2010 12:02 PM
  • User1322403867 posted

    atconway,

     

    Thanks for your extensive reply!! This is exactly the sort of knowledge I was looking for. I always want to hear the reasoning behind choosing one method or another so I have confidence, so you have helped me greatly in that respect! I shall take time to read the links you have given, I'm sure I will learn a lot.

     

    Thanks,

     

    Duncan   

    Friday, February 12, 2010 1:26 PM