简体   繁体   English

我如何URL正确重写图像? C#ASP.NET

[英]How do i URL rewrite an image properly? C# ASP.NET

I tried several ways to URL rewrite. 我尝试了几种URL重写的方法。 The first way the image mime was clobbered and was consider an octet stream which didnt allow me to view the image in a browser (unless it was using img src). 图像模仿的第一种方式是被破坏,并且被认为是八位字节流,它不允许我在浏览器中查看图像(除非它使用的是img src)。 The 2nd way i wasnt convince it worked. 我不相信它的第二种方法。 Firefox displayed the img but said the length was 0 (i think it only worked bc it was in my cache). Firefox显示了img,但表示长度为0(我认为它仅在我的缓存中有效)。

How do i properly rewrite the image /abc/id/title.png to the internal location /static/user/name/id.png 如何将图像/abc/id/title.png正确重写到内部位置/static/user/name/id.png

In ASP.NET I might do something like this: 在ASP.NET中,我可能会执行以下操作:

Response.Clear();
Response.ContentType = profile.AvatarMimeType;
Response.BinaryWrite(profile.Avatar.ToArray());

Where profile.AvatarMimeType is an appropriate mime type for a gif, jpeg, or png. 其中profile.AvatarMimeType是gif,jpeg或png的合适的mime类型。

And where profile.Avatar.ToArray() is a binary content from the db sent out as an array of data! 其中profile.Avatar.ToArray()是数据库中作为数据数组发送的二进制内容!

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

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