C# 如何使用C将html文件从数据库预览到浏览器#

C# 如何使用C将html文件从数据库预览到浏览器#,c#,database,file,preview,C#,Database,File,Preview,我将HTML代码存储在数据库中,并希望将其显示(呈现)到视图中 我想把它显示为一个普通的文本页面 eg: **HTML:** <h3 style="font-weight: bold">Usage:</h3> <p style="text-decoration: underline">Viewing of Form -</p> Should be shown as: Usage: Viewing of Fo

我将HTML代码存储在数据库中,并希望将其显示(呈现)到视图中

我想把它显示为一个普通的文本页面

eg: **HTML:** <h3 style="font-weight: bold">Usage:</h3>
<p style="text-decoration: underline">Viewing of Form -</p>

Should be shown as: Usage:
                    Viewing of Form -
我创建了一个新的page view.aspx,并尝试使用
System.Web.HttpUtility.HtmlDecode(Request.QueryString[“Text”])
来呈现文件

但我得到的是一张空白页

请帮帮我


谢谢,

您能确认
page.Text
在呈现时有值吗

如果您确定值
page.Text
填充正确(我假设类似于
“view.aspx?id=1&Text=example post”
),那么您可能希望在将URL返回到客户端之前尝试对字符串进行编码

string url = ("view.aspx?id = " + page.ID + "&Text=" + System.Web.HttpUtility.UrlEncode(page.Text));
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + url + "', null, 'height=500,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=yes' );", true);

然后确保在客户端的链接中获得编码字符。

Yes page.text在调试时具有该值。我在我的view.aspx页面中尝试了System.Web.HttpUtility.HtmlEncode(page.Text),但弹出页面中没有显示任何数据。我没有使用MVC。实际上,我可以在新窗口中看到普通文本文件,但html文本显示出现错误。我想我必须对html文件进行编码和解码。我可以如何对html文件进行编码和解码?好的,我删除了我的上一条评论,因为我认为我为您提供了不同的解决方案,但根据您的上一条评论,也许可以尝试使用
HttpUtility.UrlEncode
HttpUtility.UrlDecode
。我突然想到,因为您在查询字符串中传递这些值,HtmlEncode/Decode可能没有正确编码字符。我更新了我的答案以反映UrlEncode的使用,如果有机会,请标记为已回答:)
string url = ("view.aspx?id = " + page.ID + "&Text=" + System.Web.HttpUtility.UrlEncode(page.Text));
ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", "window.open( '" + url + "', null, 'height=500,width=800,status=yes,toolbar=yes,menubar=no,location=no,scrollbars=yes,resizable=no,titlebar=yes' );", true);