Home > Net >  About the Response. The problem of the ContentType?
About the Response. The problem of the ContentType?

Time:10-09

Captcha code below, the bottom line 4, & lt; This. The Response. ContentType="image/jpeg";> What is the significance of the existence, I don't understand? I switch to "text/HTML", "text/plain", "application/x - excel"... All don't see what effect, this didn't affect directly deleted, F5 debugging is out of the authentication code, a great god to explain,

Public partial class _Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
Bitmap BMP=new Bitmap (80, 40).
Graphics g=Graphics. FromImage (BMP);
Right to Lear (Color. White);
G.D rawRectangle (Pens. Black, 0, 0, 79, 39);
Color [] colors={Color. Black Color. Red Color, Blue, Color, DarkGreen, Color, Purple, Color. The DarkGoldenrod, Color. The Chocolate};
String [] fontNames={" tahoma ", "regular script _GB2321", "the official script", "Arial", "Comic Sans MS", "Microsoft Sans Serif", "Times New Roman"};
The Random rand=new Random ();
Char [] CHS=new char [] {(char) (65 + rand. Next (26)), (char) (65 + rand. Next (26)), (char) (65 + rand. Next (26))};
Brush Brush;
The Font Font;
Int x, y;
for (int i=0; I & lt; 3; I++)
{
Brush=new SolidBrush (colors [rand. Next (7)]);
The font=new font (fontNames [rand. Next (7)], 18, FontStyle. Bold);
X=I * 20 + 2;
Y=5 + rand. Next (5);
G.R otateTransform (rand. Next (9) - 10);
G.D rawString (CHS [I] the ToString (), the font, brush, x, y);
}

Pen [] pens={pens. Gray, pens. LightGray};
for (int i=0; I & lt; 200; I++)
{
X=rand. Next (BMP. Width - 1);
Y=rand. Next (BMP. Height - 1);
G.D rawEllipse (pens [I % 2], the x, y, 1, 1);
}


MemoryStream ms=new MemoryStream ();
BMP. Save (ms, ImageFormat. Jpeg);
This. The Response. The Clear ();
This. The Response. ContentType="image/jpeg";//this code? Look not to come out when I use the F5 debugging, it didn't seem to not the difference?
This. The Response. BinaryWrite (Ms. ToArray ());
G.D ispose ();
BMP. The Dispose ();
}
}

CodePudding user response:

This is not very clear, but I used to see in the video mentioned that, ContentType refers to return to the type of the data content, even if you don't write here, the client can also be identified what you to come over, you write "text/HTML", "text/plain", "application/x - excel" these things, you just made a cheat the client's action, is just like you give others to transfer 100 dollars, in remarks you tell others I turn to you for ten thousand, but when others received will know just 100, concrete was not so clear,
  • Related