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.ContentTy pe = "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.Respons e.OutputSt ream, System.Drawing.Imaging.Ima geFormat.J peg);
}
catch (Exception ee)
{
context.Response.Write(ee. Message.To String());
}
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 .
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.Response.ContentTy
string textToWrite = "Text Of Title Tag "; //we need to replace This Text with the real Title Of The page.
if (textToWrite.Trim().Length
{
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.Respons
}
catch (Exception ee)
{
context.Response.Write(ee.
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 .
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 .
ASKER
1-pass The Title as querystring.
2-Make New Request.
thank you.