如何建立评论页?

时间:2023-01-24 23:07:25

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?

如何建立一个页面,让访问者可以在页面上添加评论?我知道有db的时候是有可能的,问题是,我可以不用db吗?也许通过将一个新元素保存到正确的位置(在插入最后一个注释之后)的现有.aspx文件中,我该如何做呢?

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?

我在这种情况下不使用db的原因是为了简单和快速加载页面——我的方法正确吗?

5 个解决方案

#1


1  

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.

这就是我的建议。将你的推荐附加到一个有文件的文件中。AppendText,然后包含使用此命令的文件,在您希望看到此注释的地方。

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

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

不要在aspx文件中添加注释,因为这会导致重新编译您的站点。

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.

就像我说的,这是一个简单的想法,对于快速和低成本的东西。您需要在这里通过javascript注入和垃圾邮件来处理攻击,但您没有权限批准/拒绝消息。

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

这肯定是最快速、最简单的方法——但是您无法控制评论。

#2


1  

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.

您需要将数据存储在某处,并在稍后查询它。你打算怎么做?您确实需要某个地方存储该信息,而db是最好的选择。

#3


1  

can I do it without a db?

我可以不用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.

你可以用你的脚来驾驶你的车,这并不一定是一个好主意。使用数据库有很多好处,比如安全性、并发性和性能。你应该把这看成是为工作选择正确的工具而不是重新发明*的机会。

#4


0  

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

net站点有大量的教程,从静态页面到数据驱动页面:

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.

你可能希望沿着微软所说的“网页”的路线走下去,“网页”是更简单但更基本的版本,它有更大的兄弟网络表单和mvc框架。

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

下面是指向“web页面”的数据教程的直接链接:http://www.asp.net/webpages/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-pages

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

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

http://www.asp.net/mvc

http://www.asp.net/mvc

#5


0  

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.

创建一个div,在您的aspx页面上,您可以将这个div命名为“comments”或其他。这里只有注释。你要做的是创建一个通用的表单,可能有一个注释的文本区域,和一个提交按钮。当单击submit按钮时,它将触发一个事件,该事件使用streamwriter直接写入文本文件。您需要能够循环遍历文本文件的行,直到找到您的div,然后它将把html写到文本文件并保存它。这意味着,当您使用streamwriter时,您将会有所有的代码,以便对已经存在的注释进行格式化,并且只抓取评论的用户名和文本。

#1


1  

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.

这就是我的建议。将你的推荐附加到一个有文件的文件中。AppendText,然后包含使用此命令的文件,在您希望看到此注释的地方。

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

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

不要在aspx文件中添加注释,因为这会导致重新编译您的站点。

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.

就像我说的,这是一个简单的想法,对于快速和低成本的东西。您需要在这里通过javascript注入和垃圾邮件来处理攻击,但您没有权限批准/拒绝消息。

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

这肯定是最快速、最简单的方法——但是您无法控制评论。

#2


1  

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.

您需要将数据存储在某处,并在稍后查询它。你打算怎么做?您确实需要某个地方存储该信息,而db是最好的选择。

#3


1  

can I do it without a db?

我可以不用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.

你可以用你的脚来驾驶你的车,这并不一定是一个好主意。使用数据库有很多好处,比如安全性、并发性和性能。你应该把这看成是为工作选择正确的工具而不是重新发明*的机会。

#4


0  

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

net站点有大量的教程,从静态页面到数据驱动页面:

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.

你可能希望沿着微软所说的“网页”的路线走下去,“网页”是更简单但更基本的版本,它有更大的兄弟网络表单和mvc框架。

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

下面是指向“web页面”的数据教程的直接链接:http://www.asp.net/webpages/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-pages

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

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

http://www.asp.net/mvc

http://www.asp.net/mvc

#5


0  

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.

创建一个div,在您的aspx页面上,您可以将这个div命名为“comments”或其他。这里只有注释。你要做的是创建一个通用的表单,可能有一个注释的文本区域,和一个提交按钮。当单击submit按钮时,它将触发一个事件,该事件使用streamwriter直接写入文本文件。您需要能够循环遍历文本文件的行,直到找到您的div,然后它将把html写到文本文件并保存它。这意味着,当您使用streamwriter时,您将会有所有的代码,以便对已经存在的注释进行格式化,并且只抓取评论的用户名和文本。

相关文章