2012-06-19 6 views
0

나는 서버의 폴더에 저장된 사진과 SQL 서버에 저장된 사진의 포인터가있는 asp.net 및 sql 서버를 사용하여 많은 사진을 표시하는 웹 사이트를 가지고 있습니다. iis7이 설치된 Windows 컴퓨터에서 웹 사이트를 호스팅했으며 동일한 컴퓨터에서 웹 사이트를 볼 때 Temp Internet Files 폴더에있는 사진을 찾을 수 없습니다. 웹 사이트가 아직 온라인 상태가 아니기 때문에 다른 컴퓨터 사용에 대해 확신하지 못합니다. 여기서 무슨 일이 일어나고있는거야? 내가 잘못한 일을하고 있거나 IE가 localhost에서 임시 폴더로 그림을 다운로드하지 않습니까 ??asp.net : 내 웹 사이트를 볼 때 내 임시 인터넷 파일 폴더에서 사진을 찾을 수없는 이유는 무엇입니까?

답변

1

다음은 서버에 저장된 다른 폴더의 이미지를 표시하고 싶습니다. 저는 새로운 것이므로 가장 효율적이거나 최선의 방법은 아니지만 작동하며 원하는 결과를 얻기 위해 코드를 변경하는 방법에 대한 아이디어를 줄 수도 있습니다.

1) 서버의 경로를 appSettings의 web.config에 추가합니다.

<configuration> 

    <appSettings> 
    <add key="ClientContactBusinessCardImagePath" value="C:\Content\BusinessCards\" /> 
    <add key="SupportLogPDFPath" value="C:\Content\SupportLogPDFs\" /> 
    <add key="NewsAttachmentPath" value="C:\Content\NewsAttachments\" /> 
    </appSettings> 
    <system.web> 
    //etc. 
    </system.web> 
</configuration> 

2) 다음은 서버에 저장된 폴더에서 명함을 표시하는 내 방법이지만, 프로젝트의 일부가 아닌 :

private void showBusinessCard(int setwidth) 
{ 
    float fileWidth; 
    float fileHeight; 
    float sizeratio; 
    float calculatedheight; 
    int roundedheight; 
    try 
    { 
     FileStream fstream = new FileStream(WebConfigurationManager.AppSettings["ClientContactBusinessCardImagePath"] + BusinessCardLabel.Text, FileMode.Open, FileAccess.Read, FileShare.Read); 
     System.Drawing.Image image = System.Drawing.Image.FromStream(fstream); 
     fstream.Dispose(); 
     fileWidth = image.Width; 
     fileHeight = image.Height; 
     sizeratio = fileHeight/fileWidth; 

     calculatedheight = setwidth * sizeratio; 
     roundedheight = Convert.ToInt32(calculatedheight); 

     imgbusinesscard.Width = setwidth; 
     imgbusinesscard.Height = roundedheight; 

     imgbusinesscard.ImageUrl = "ImageHandler.ashx?img=" + BusinessCardLabel.Text; 
     hlbusinesscard.NavigateUrl = "ImageHandler.ashx?img=" + BusinessCardLabel.Text; 
    } 
    catch 
    { 
     imgbusinesscard.ImageUrl = "~/images/editcontact/businesscard-noimage.png"; 
     imgbusinesscard.Width = 240; 
     imgbusinesscard.Height = 180; 
    } 

3) 그리고 호출되는 ImageHandler 중간에 다음과 같이 보입니다.

public void ProcessRequest(HttpContext context) 
{ 
    try 
    { 
     string imageFileName = context.Request.QueryString["img"]; 

     System.Drawing.Image objImage = System.Drawing.Bitmap.FromFile(Path.Combine(WebConfigurationManager.AppSettings["ClientContactBusinessCardImagePath"], imageFileName)); 

     if (imageFileName != null) 
     { 
      MemoryStream objMemoryStream = new MemoryStream(); 
      objImage.Save(objMemoryStream, System.Drawing.Imaging.ImageFormat.Jpeg); 
      byte[] imageContent = new byte[objMemoryStream.Length]; 
      objMemoryStream.Position = 0; 
      objMemoryStream.Read(imageContent, 0, (int)objMemoryStream.Length); 
      objMemoryStream.Dispose(); 
      objImage.Dispose(); 
      context.Response.ContentType = "image/jpeg"; 
      context.Response.BinaryWrite(imageContent); 
     } 
    } 
    catch { } 
} 
+0

요점은? – Aperture

+0

글쎄, 솔직히 말해서 당신의 질문은 다소 모호했습니다.하지만 질문을 대답하지 않은 질문들 속에 가라 앉히기보다는, 나는 우리에게 아직 실패한 작업 코드를 제공 할 것입니다. 문제 해결 방법에 대한 다른 방향을 생각하게하십시오. 맞춰 보지 않았나. – CptSupermrkt

관련 문제