【问题标题】:Asp.net Programming, output to HTML instead of writing to the consoleAsp.net编程,输出到HTML而不是写到控制台
【发布时间】:2020-11-01 16:38:30
【问题描述】:

我编写了一个 Azure 函数来从 blobstorage 中读取 blob 内容。这很好用,但我怎样才能将此数据发送到我的 .html 模板而不是将信息写入控制台?

在附件中,我有一张解释我的问题的图片。我对 c# 和 azure 函数非常陌生。

2020 年 7 月 12 日更新: 我尝试了另一种解决方案,但代码有问题?

enter image description hereimgur.com/VX2J7.png

【问题讨论】:

  • using(var reader = new StreamReader(myBlob); 应该是using(var reader = new StreamReader(myBlob)).......
  • 伟大的 Seabizkit。我会试试这个。

标签: c# html asp.net azure-functions azure-blob-storage


【解决方案1】:

如果 'oldContent' 是有效的 html,那么你可以按照这个思路做一些事情。

 public static class MyFunction
 {
    [FunctionName("BlobTrigger")]
    public static async Task<IActionResult> RunAsync([BlobTrigger("samples-workitems/{name}", Connection = "")]
        Stream myBlob, string name, ILogger log)
    {
        log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
        using (var reader = new StreamReader(myBlob))
        {
            var content = await reader.ReadToEndAsync();
            return new ContentResult
            {
                Content = content,
                ContentType = "text/html"
            };
        }
    }
}

【讨论】:

  • 感谢 Tom,但我尝试使用您的代码,Visual Studio 告诉“reader.ReadToEnd()”和“return”语句行仍然存在语法错误。你能检查一下吗?谢谢
  • 我已经更新了示例代码,有关使用流的更多信息,请参阅本指南 - docs.microsoft.com/en-us/dotnet/api/…
猜你喜欢
  • 1970-01-01
  • 2021-12-07
  • 1970-01-01
  • 2016-03-29
  • 1970-01-01
  • 2021-05-12
  • 2020-04-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多