Link to home
Start Free TrialLog in
Avatar of alharbin
alharbin

asked on

How To Access HTML Title Tag By IHttpHandler ?

as you see , we have HTML File And ASHX File .

The HTML File Containing Image Tag , The SRC Value Of The Image Is our ASHX File .

When We Open The HTML File The ASHX Creating Image On-fly Containing some text .we need to Access The real Title Tag Of The HTML Page and Print it On the Image instead The Static Text


1-askexpert.ashx
C Sharp Code

    public class specialimage : IHttpHandler
    {
       
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "image/jpeg";
            string textToWrite = "Text Of Title Tag "; //we need to replace This Text with the real Title Of The page.
            if (textToWrite.Trim().Length > 0)
            {
                Bitmap image = new Bitmap(400, 30);
                Graphics g = null;            
                try            
                {                
                    g = Graphics.FromImage(image);                
                    Font f = new Font("Arial", 10, FontStyle.Regular);                
                    SolidBrush b = new SolidBrush(Color.White);                
                    g.FillRectangle(b, 0, 0, 400, 30);                
                    g.DrawString(textToWrite, f, Brushes.Blue, 2, 5);                
                    f.Dispose();                
                    image.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);            
                }            
                catch (Exception ee)            
                {                
                    context.Response.Write(ee.Message.ToString());            
                }            
                finally            
                {                
                    image.Dispose();                
                    g.Dispose();            
                }        
            }    
        }
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }

2-index.htm ,
Containing one Image Element

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>This Is Index Page</title>
</head>
<body>
        <img alt="" src="specialimage.ashx" />
</body>
</html>

The SRC Value Is Our ASHX File .

SOLUTION
Avatar of rodmjay
rodmjay
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alharbin
alharbin

ASKER

we need to access the title Tag directly from The Handler Code, we must avoid :
1-pass The Title as querystring.
2-Make New Request.

thank you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think you are worthy of Master , your reply is logical .
but i hope find a way to access HTML Tags from Server side script with or witout HTTP Handler class...

thank you again for help .