HTML保存的文件是什么,如何获取我保存的html文件而不是显示原始html?

博客讨论了一个WinForms应用程序通过电子邮件发送包含HTML链接的报告的问题。当用户点击链接,WebAPI返回HTML文件,但浏览器显示原始HTML代码而非格式化的内容。问题在于如何让返回的HTML在浏览器中正确渲染。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我有保存在Web API应用程序的App_Data文件夹中的html文件。一个同伴客户端(的WinForms)应用程序发送一封电子邮件,其中一个链接,让用户点击该链接,查看这些HTML文件,在浏览器中,像这样:如何获取我保存的html文件而不是显示原始html?

// Client Winforms app code

internal static bool EmailGeneratedReports(string emailAddr)

{

bool success = true;

try

{

Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

MailItem mailItem = app.CreateItem(OlItemType.olMailItem);

mailItem.Subject = String.Format("duckbillP Reports generated {0}", GetYYYYMMDDHHMM());

mailItem.To = emailAddr;

string rptLinks = String.Format("Price Compliance Report Online", ReportRunnerConstsAndUtils.SERVER_BASE_ADDRESS, "Platypus", "gramps", "201507"); // hardcoding year and month for now

mailItem.HTMLBody = String.Format("

Your duckbillP reports are attached. You can also view them online here:

{0}", rptLinks);

FileInfo[] rptsToEmail = GetLastReportsGenerated();

foreach (var file in rptsToEmail)

{

mailItem.Attachments.Add(String.Format("{0}\\{1}", uniqueFolder, file.Name));

}

mailItem.Importance = OlImportance.olImportanceHigh;

mailItem.Display(false);

}

catch (System.Exception sysex)

{

String sysexDetail = String.Format(ReportRunnerConstsAndUtils.ExceptionFormatString, sysex.Message,

Environment.NewLine, sysex.Source, sysex.StackTrace);

MessageBox.Show(sysexDetail);

success = false;

}

return success;

}

在Web API应用程序的获取代码运行良好;这是在点击链接时,什么叫做:

// Web API (server) Controller code

[Route("{unit}/{begindate}")]

public string Get(string unit, string begindate)

{

string _unit = unit;

string _begindate = String.Format("{0}01", PlatypusWebReportsConstsAndUtils.HyphenizeYYYYMM(begindate));

string appDataFolder = HttpContext.Current.Server.MapPath("~/App_Data/");

string htmlSummaryFilename = string.Format("platypusSummary_{0}_{1}.html", _unit, _begindate);

string fullSummaryPath = Path.Combine(appDataFolder, htmlSummaryFilename);

string htmlDetailFilename = string.Format("platypusDetail_{0}_{1}.html", _unit, _begindate);

string fullDetailPath = Path.Combine(appDataFolder, htmlDetailFilename);

String summaryHtmlFromFile = File.ReadAllText(fullSummaryPath);

String detailHtmlFromFile = File.ReadAllText(fullDetailPath);

return String.Format("{0}
{1}", summaryHtmlFromFile, detailHtmlFromFile);

}

我希望返回的HTML中以正常的方式浏览器将呈现,但不是,它只是显示了原始的HTML(包括所有的角括号和html关键字等)。 IOW,看起来如果我在记事本中查看HTML,而不是在浏览器中。

我怎样才能看到GET方法返回的HTML按预期显示?

要非常清楚,我不希望用户看到这样的东西:

This is heading 1 (Candara)

This is heading 2 (Georgia)

This is heading 3 (Tahoma)

This is a Candara 1.1em paragraph

This is a Segoe UI paragraph

This is a Tahoma paragraph

This is a Georgia 1.1em paragraph

...而是呈现的HTML这样的:

aJox7.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值