ASP.NET MVC页面上远程服务器的显示图像 [英] Dispaly image from remote server on the page ASP.NET MVC

查看:79
本文介绍了ASP.NET MVC页面上远程服务器的显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过保存在数据库中的路径显示照片像这样\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg。我有mothod来转换路径

public FileContentResult ImagePath(string path)
{

string str1 =C:/;
string str2 =//94.19.247.273/C$//;
string result = path.Replace(str2,str1);

byte [] imageArray = System.IO.File.ReadAllBytes(result);
返回新的FileContentResult(imageArray,image / png);
}
我从Stackoverflow得到它,并在View上看到这样的

@foreach(Model.ProductPhotoPathList中的var项目)
{
< li data-thumb =@ Url.Action(ImagePath,Home,new {path = item})>
< div class =thumb-image> < img src =@ Url.Action(ImagePath,Home,new {path = item})data-imagezoom =trueclass =img-responsivealt => < / DIV>
< / li>
}
但是当页面加载ImagePath方法成功运行时,这是一个问题但是在页面上我仍然得到保存在数据库上的路径\\\\94.19.247.273 \ C $ \ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\我想得到这样的道路:C:\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\问题可能是?





我尝试过:



我有这条路径/Home/ImagePath?path=%2F%2F94.19.247.273%2FC%24%2F%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18 -_11-20-02.jpg。 

所以我想把它转换为/Home/ImagePath?path=C%3A%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg。

该方法正确转换它但我无法在页面上获取它。

解决方案

\\\ \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\我有mothod来转换路径

public FileContentResult ImagePath(string path)
{

string str1 =C:/;
string str2 =//94.19.247.273/C


//;
string result = path.Replace(str2,str1);

byte [] imageArray = System.IO.File.ReadAllBytes(result);
返回新的FileContentResult(imageArray,image / png);
}
我从Stackoverflow得到它,并在View上看到这样的

@foreach(Model.ProductPhotoPathList中的var项目)
{
< li data-thumb =@ Url.Action(ImagePath,Home,new {path = item})>
< div class =thumb-image> < img src =@ Url.Action(ImagePath,Home,new {path = item})data-imagezoom =trueclass =img-responsivealt => < / DIV>
< / li>
}
但是当页面加载ImagePath方法成功运行时出现问题但在页面上我仍然得到保存在数据库上的路径\\\94.19.247.273 \ C

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\我无法在页面上更改路径。我想得到这样的路径:C:\t\q\laptop.com \bb\images\UrunImages\a1\ 14-09-18 -_04-17-00.jpg问题可能是什么?





我尝试了什么:



我有这条路径/Home/ImagePath?path=%2F%2F94.19.247.273%2FC%24%2F%2FBaburtechAnakartImage%2FACER_murtaza %20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg。 

所以我想把它转换为/Home/ImagePath?path=C%3A%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg。

方法正确转换它但我无法在页面上获取它。


I want to display the photo through the Path which is saved on the database Like this \\94.19.247.273\C$\\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg . I have mothod to convert the path

 public FileContentResult ImagePath(string path)
    {

        string str1 = "C:/";
        string str2 = "//94.19.247.273/C$//";
        string result = path.Replace(str2, str1);

        byte[] imageArray = System.IO.File.ReadAllBytes(result);
        return new FileContentResult(imageArray, "image/png");
    }
I get it from Stackoverflow and on the View like this

  @foreach (var item in Model.ProductPhotoPathList)
                {
                    <li data-thumb="@Url.Action("ImagePath","Home",new { path = item})">
                        <div class="thumb-image"> <img src="@Url.Action("ImagePath","Home",new { path = item})" data-imagezoom="true" class="img-responsive" alt=""> </div>
                    </li>
                }
but here is a problem when page load ImagePath method work successfully but on the page i still get the Path like which is saved on the database \\94.19.247.273\C$\\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg, so i can not get changed path on the page.I want to get path like this :C:\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg what the problem might be?



What I have tried:

i have this path /Home/ImagePath?path=%2F%2F94.19.247.273%2FC%24%2F%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg.

so i want to convert it to /Home/ImagePath?path=C%3A%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg.

the method convert it correctly but i can not get it on the page.

解决方案

\\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg . I have mothod to convert the path public FileContentResult ImagePath(string path) { string str1 = "C:/"; string str2 = "//94.19.247.273/C


//"; string result = path.Replace(str2, str1); byte[] imageArray = System.IO.File.ReadAllBytes(result); return new FileContentResult(imageArray, "image/png"); } I get it from Stackoverflow and on the View like this @foreach (var item in Model.ProductPhotoPathList) { <li data-thumb="@Url.Action("ImagePath","Home",new { path = item})"> <div class="thumb-image"> <img src="@Url.Action("ImagePath","Home",new { path = item})" data-imagezoom="true" class="img-responsive" alt=""> </div> </li> } but here is a problem when page load ImagePath method work successfully but on the page i still get the Path like which is saved on the database \\94.19.247.273\C


\\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg, so i can not get changed path on the page.I want to get path like this :C:\t\q\laptop.com\bb\images\UrunImages\a1\14-09-18-_04-17-00.jpg what the problem might be?



What I have tried:

i have this path /Home/ImagePath?path=%2F%2F94.19.247.273%2FC%24%2F%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg.

so i want to convert it to /Home/ImagePath?path=C%3A%2FBaburtechAnakartImage%2FACER_murtaza%20test1%2F1_ACER_murtaza%20test1_12-09-18-_11-20-02.jpg.

the method convert it correctly but i can not get it on the page.


这篇关于ASP.NET MVC页面上远程服务器的显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆