简体   繁体   English

扩展Web服务器以提供静态文件

[英]extend web server to serve static files

I want to extend a web server which is only able to handle RPC handling now. 我想扩展一个Web服务器,该服务器现在只能处理RPC处理。 The web server is written in C#. Web服务器是用C#编写的。 It provides a abstract handler function like following: 它提供了一个抽象的处理程序函数,如下所示:

public string owsHandler(string request, string path, string param,
                                      OSHttpRequest httpRequest, OSHttpResponse httpResponse)

And I wrote following code to handle image files: 我编写了以下代码来处理图像文件:

Bitmap queryImg = new Bitmap(path);
System.IO.MemoryStream stream = new System.IO.MemoryStream();
queryImg.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
queryImg.Dispose();
byte[] byteImage = stream.ToArray();
stream.Dispose();
return Convert.ToBase64String(byteImage);

And I test it in the browser, the image is returned but the image dimension info is missed. 我在浏览器中对其进行了测试,返回了图像,但是缺少图像尺寸信息。 Shall I add something more to the code? 我应该在代码中添加更多内容吗? Or is any general way to server static files? 还是使用任何常规方法来处理静态文件? I do not want to serve it in a ASP.net server. 我不想在ASP.net服务器中提供它。

Thanks 谢谢

不要尝试将文件加载到内存中的位图图像中,只需按原样提供即可。

return Convert.ToBase64String(File.ReadAllBytes(path));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM