How to install Img-scr from a server that is not live but connected to the Live server

I want to display a photo of an employee who is a username, but our company does not want to publicly publish photos of all employees, so we post photos of our employees on a server that does not live, but is connected to a live server.

Now the problem is that when I launch my site on localhost, photos of employees are displayed, but as soon as I publish it on IIS, it does not display images.

Please suggest a solution.

+3
source share
4 answers

, , . . IIS.

src . IIS , . , .

+1

, , - "" , , - . - -, , ( , , ).

.NET:

protected void Page_Load(object sender, EventArgs e)
{
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ContentType = "image/jpeg";
    using (Bitmap bmp = 
        (Bitmap)Bitmap.FromFile(
            @"\\internal-photoserver\shared drive\bobsmith.jpg"))
    {
        bmp.Save(
            HttpContext.Current.Response.OutputStream,
            ImageFormat.Jpeg);
    }
    HttpContext.Current.Response.End();
}
// needs these two using statements:
using System.Drawing;
using System.Drawing.Imaging;

, , , ( ). - " ", , " ".

, . ASP.NET, , , .

: MSDN:

System.Drawing Windows ASP.NET. , .

( , , , , , ), plain-ol 'System.IO , , (- - ).

: , :

protected void Page_Load(object sender, EventArgs e)
{
    HttpContext.Current.Response.Clear();
    HttpContext.Current.Response.ContentType = "image/jpeg";
    byte[] bytes = File.ReadAllBytes(
        @"\\internal-photoserver\shared drive\bobsmith.jpg");
    HttpContext.Current.Response.OutputStream.Write(bytes, 0, bytes.Length);
    HttpContext.Current.Response.End();
}
// need this using statement:
using System.IO;

, , , ( BMP). , , , , .

, , , - (, - - , - , MSDN System.Drawing ASP.NET).

: , , , , , , , HTML- (.. ..).

, , , , , IFRAME src, .

IFRAME - , . JPEG , , . , .

ASP.NET , , . ASP.NET , .

0

HttpHandler . , - ( App_Data) , .

- , , .. . , , :

public class myPhototHandler: IHttpHandler
{    
    
    public bool IsReusable {
        get { return true; }
    }
    
    public void ProcessRequest(System.Web.HttpContext context)
    {
        
            if (Context.User.Identity.IsAuthenticated) {
                var filename = context.Request.QueryString("f") ?? String.Empty;
                string completePath = context.Server.MapPath(string.Format("~/App_Data/Photos/{0}", path));
                context.Response.ContentType = "image/jpeg";
                context.Response.WriteFile(completePath);             
            }
       
    }
    
}

, , , , .., web.config. src - myPhototHandler.ashx? F = myphoto.jpg

0

ASP.NET , . Generic Handler PhotoHandler:

<%@ WebHandler Language="C#" Class="PhotoHandler" %>

using System;
using System.Web;

public class PhotoHandler : IHttpHandler {

    public void ProcessRequest (HttpContext context) {
        string photoName = context.Request.QueryString["photoName"]; 
        context.Response.ContentType = "image/jpeg";
        context.Response.WriteFile(
            String.Format(
                @"\\internal-photoserver\shared drive\{0}.jpg", 
                photoName));
    }

    public bool IsReusable {
        get {
            return false;
        }
    }
}

, ( ) img HTML, src, , :

<img src="PhotoHandler.ashx?photoName=bob_smith" alt="If Bob Smith was a cat, 
    I would shave his ass and make him walk backwards." />

. , ( , UNC- ), .

0

Source: https://habr.com/ru/post/1744586/


All Articles