0

i'm building a class library project using c# to scale/resize images,the project only has one class with only one public static function with 2 parameters now the code is working fine and perfect so its not the issue here. now, how can i execute this function directly from url? ex:my project called: myDLL.dll how to do this:

img src="/myDLL.dll?image=/images/pic1.png&width=200"

so this execute my function and pass width and image as parameters

i know how to add iis handler to execute DLL from browser..but i dont know how to make this :/myDLL.dll?image=/images/pic1.png&width=200 run my function

plz help

  • That is not gonna work. To serve images like that you need something like a generic handler: https://stackoverflow.com/questions/8733875/display-image-using-ashx-handler – VDWWD Oct 30 '17 at 13:36
  • VDWWD see this for example: http://www.menafn.com/charting/Imager.dll?Image=/updates/pr/2017-10/N_9519389e-5image_story.jpg&height=155&Compression=80 – Dhananny3 Hanny Oct 30 '17 at 13:49
  • I highly doubt that it is an actual Library file. And even if it were they would have to lower security settings to such a level that .dll files would be able to be requested by a browser (which is not a good idea) – VDWWD Oct 30 '17 at 13:53
  • well,this is a dll file and i can send it to you via email to test it on any website.... our company use it to scale image on website ...but we notice some error on it so we decided to write a new code ......the issue is i can not know how the previous guy did this trick to run dll file – Dhananny3 Hanny Oct 30 '17 at 13:55

1 Answers1

0

Yes, you can.

HTTP Handler

public class Class1 : IHttpHandler
{
  public bool IsReusable => false;

  public void ProcessRequest(HttpContext context)
  {
    Assembly ass = Assembly.LoadFile(context.Request.PhysicalPath);
    Type[] assemblyTypes = ass.GetTypes();
    for (int j = 0; j < assemblyTypes.Length; j++)
    {
      if (assemblyTypes[j].Name == "WebDLL")
      {
        object o = Activator.CreateInstance(assemblyTypes[j]);
        MethodInfo mi = assemblyTypes[j].GetMethod("ProcessRequest");
        mi.Invoke(o, new object[] { context });
      }
    }
  }
}

DLL

public class WebDLL
{
  public void ProcessRequest(HttpContext context)
  {
    context.Response.Write("Hello World!");
  }
}

It will output Hello World!

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
huseyin
  • 25
  • 6