使用 linq to sql 和 HtmlEncode

发布于 2024-07-29 02:15:42 字数 333 浏览 1 评论 0原文

我正在使用 linq-to-sql 加载数据并将数据保存到数据库。 的摘要

  1. 由于要保存或加载的大多数数据都是用户输入,为了避免保存原始数据的所有可能的风险,我决定对输入进行 HtmlEncode。以下是我在将输入保存到数据库之前对输入进行编码
  2. 。 解码输入以便能够操作原始数据。
  3. 重新编码输入以显示给用户。

问题是我必须创建另一个业务对象来将从数据库获取的数据转换为用户输入的实际原始数据,从而使我的 linq 业务对象有些无用。

难道我做错了什么? 如果我使用 ling to sql,我真的需要将数据转换为数据库吗?

I am using linq-to-sql to load and save data to database. Since most of the data to save or load is user input and to avoid all possible risks of saving raw data, i decided to HtmlEncode the input.Here is the summary of what I do

  1. Encode the input before saving it to the database.
  2. Decode the input to be able to manipulate the raw data.
  3. re-Encode the input for display to the user.

The problem is that I had to create another business object to convert the data I get from the database to the actual raw data the user entered, thus rendering my linq business object somewhat useless.

Am I doing something wrong? Do I really need to convert the data on its way to the database if I am using ling to sql?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

天荒地未老 2024-08-05 02:15:42

听起来您应该将原始数据存储在数据库中,然后在将其显示给用户之前始终对其进行编码。 使用 LINQ to SQL 时不必担心 SQL 注入,因为它在幕后使用参数化查询。

It sounds like you should store the data raw in the database, and then always encoded it before displaying it to the user. You do not have to worry about SQL injections when you're using LINQ to SQL, since it is using parameterized queries behind the scenes.

悍妇囚夫 2024-08-05 02:15:42

只需将原始 HTML 存储到数据库中,并在公开显示它时使用 HTMLEncode()(或者更好的是 Microsoft 的反跨站脚本库的 HTMLEncode() 方法)。

http://www.microsoft.com/downloads/details.aspx microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&displaylang=en

Just store the raw HTML into your database, and use HTMLEncode() (or even better, Microsoft's Anti-Cross Site Scripting Library's HTMLEncode() method) when you're displaying it publicly.

http://www.microsoft.com/downloads/details.aspx?FamilyId=051ee83c-5ccf-48ed-8463-02f56a6bfc09&displaylang=en

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文