BornToCode
BornToCode

Reputation: 10213

How can I build a comments page?

How to build a page where visitors can add comments to the page? I know it's possible with a db, the question is - can I do it without a db? Perhaps by saving a new element to the existing .aspx file in the correct location (after the last comment inserted), how do I do it?

Any other elegant idea how to implement this?

The reason I don't use a db in this case is for simplicity and for fast loading of the page - am I right with my approach?

Upvotes: 1

Views: 459

Answers (5)

Mr Wilde
Mr Wilde

Reputation: 659

can I do it without a db?

You can steer your car with your feet, that doesn't necessarily make it a good idea. There are so many benefits to using a database such as security, concurrency and indeed performance. You should look at this as an opportunity to pick the right tool for the job rather than reinventing the wheel.

Upvotes: 1

Tony318
Tony318

Reputation: 562

I still suggest using a database but this is basically the thought process i have of doing it your way. I have never done this so it is just going to be theory not code and someone may need to add to it.

Create a div where you want your comments on your aspx page, you can name this div "comments" or something. Only comments go in here though. What you are going to do is make a generic form probably having a text area for the comments, and a submit button. When the submit button is pressed it triggers an event that uses a streamwriter to directly write to the text file. You need to be able to loop through the lines of the text file until you hit your div and then it will write the html to the text file and save it. This means when you use your streamwriter you are going to have all the code laid out for the formatting of the comment already there and are just grabbing the user name and text of the comment.

Upvotes: 0

Alex KeySmith
Alex KeySmith

Reputation: 17101

The asp.net site has a great set of tutorials from moving from static pages into data driven pages:

You may wish to go down the route that microsoft describtes as "web pages", which is the easier but more basic version of it's bigger brothers web-forms and mvc-framework.

Here is a direct link to the data tutorials for "web pages": http://www.asp.net/web-pages/tutorials/data

Looking at these tutorials will help you descide which is best for you.

But you may wish to look at:

http://www.asp.net/web-pages

http://www.asp.net/web-forms

http://www.asp.net/mvc

Upvotes: 0

Aristos
Aristos

Reputation: 66641

I also suggest the use of a database, how ever some time we need to make something low cost, simple and fast for a small web site with not so many traffic.

So this is what I suggest you. Appends your commends to a file with File.AppendText, and then include the file using this command, on the place you like to see this comments.

<!--#include file="CommentsA.htm"--> 

Do not append your comments in the aspx file because this can cause recompile of your site.

As I say again, this is a simple idea, for something fast and low cost. You need here to take care the attacks via javascript injection and the spam, nether you have the luxury to approve/reject messages.

This is for sure the faster and easiest way - but you do not have control over the comments.

Upvotes: 1

Diego
Diego

Reputation: 36146

No!

You need to store your data somewhere and query it latter on. How do you expect to do it? You definitively need somewhere to store that information and a db is the best option.

Upvotes: 1

Related Questions