c#Azure函数将html和css分开

c#Azure函数将html和css分开,c#,azure,azure-functions,C#,Azure,Azure Functions,我目前正在使用Azure函数为内部系统生成html页面;因此,它不需要为我的需要托管在web服务器上。Iv目前正在将html复制并粘贴到字符串变量中,并将其作为响应返回。然而,这意味着我必须将CSS和html组合成一个大的长字符串,这很难组织和管理 有没有办法将html和css分离成单独的文件,并将其链接到azure函数作为响应 结构示例: \View\HomePage\HomePage.html,HomePageAzureFunction.cs \View\Style\Style.css \

我目前正在使用Azure函数为内部系统生成html页面;因此,它不需要为我的需要托管在web服务器上。Iv目前正在将html复制并粘贴到字符串变量中,并将其作为响应返回。然而,这意味着我必须将CSS和html组合成一个大的长字符串,这很难组织和管理

有没有办法将html和css分离成单独的文件,并将其链接到azure函数作为响应

结构示例:

  • \View\HomePage\HomePage.html,HomePageAzureFunction.cs
  • \View\Style\Style.css
  • \View\Javascript\Javascript.js
有没有办法将html和css分离成单独的文件,并将其链接到azure函数作为响应

您可以利用或ftp工具访问azure功能文件,然后添加相关目录和文件(html、css等),如下所示:

https://<your-functionapp-name>.azurewebsites.net/<your-HttpTriggerName>/view/style/site.css
<link rel="stylesheet" href="https://{your-storage-account}.blob.core.windows.net/{container-name}/view/style/site.css">

<script src="https://{your-storage-account}.blob.core.windows.net/{container-name}/view/javascript/site.js"></script>

run.csx:

#r“System.Web”
使用System.Web;
Net系统;
使用System.Net.Http.Header;
公共静态HttpResponseMessage运行(HttpRequestMessage请求,TraceWriter日志)
{ 
var response=req.CreateResponse(HttpStatusCode.OK);
var stream=new FileStream(@“d:\home\site\wwwroot\HttpTriggerCSharp4\view\home\index.html”,FileMode.Open);
response.Content=新的流内容(stream);
response.Content.Headers.ContentType=新的MediaTypeHeaderValue(“文本/html”);
返回响应;
}
注意:无法按如下方式正确加载css和javascript文件:

https://<your-functionapp-name>.azurewebsites.net/<your-HttpTriggerName>/view/style/site.css
<link rel="stylesheet" href="https://{your-storage-account}.blob.core.windows.net/{container-name}/view/style/site.css">

<script src="https://{your-storage-account}.blob.core.windows.net/{container-name}/view/javascript/site.js"></script>
https://.azurewebsites.net//view/style/site.css
对于这种情况,您可能需要添加其他HttpTrigger端点来访问css和javascript文件。对我来说,我会使用Azure Blob存储来存储CSS和javascript文件,您可以遵循这些详细信息。您可以在html文件中添加css和javascript文件,如下所示:

https://<your-functionapp-name>.azurewebsites.net/<your-HttpTriggerName>/view/style/site.css
<link rel="stylesheet" href="https://{your-storage-account}.blob.core.windows.net/{container-name}/view/style/site.css">

<script src="https://{your-storage-account}.blob.core.windows.net/{container-name}/view/javascript/site.js"></script>


你的意思是你仍然希望在一次响应中从Azure函数返回所有3个文件,还是返回带有css/js链接的HTML,然后分别调用来检索这些文件?我的感觉是Azure函数并不是为了取代MVC应用而设计的。你最好有一个客户端应用程序(你可以在Azure CDN或任何CDN上托管它),Azure函数将成为你的API。