Thuộc tính ContentType của ASP
Thuộc tính ContentType thiết lập loại nội dung HTTP cho đối tượng response.
Cú pháp:
response.ContentType[=contenttype]
Tham số | Mô tả |
---|---|
contenttype |
Chuỗi mô tả loại nội dung. Để có danh sách đầy đủ các loại loại nội dung, hãy xem tài liệu trình duyệt của bạn hoặc tiêu chuẩn HTTP. |
Mô hình
Nếu trang ASP không thiết lập thuộc tính ContentType, thì đầu content-type mặc định sẽ như sau:
content-type:text/html
Một số giá trị.ContentType thường dùng khác:
<%response.ContentType="text/HTML"%> <%response.ContentType="image/GIF"%> <%response.ContentType="image/JPEG"%> <%response.ContentType="text/plain"%> <%response.ContentType="image/JPEG"%>
Ví dụ này sẽ mở một bảng tính Excel trong trình duyệt (nếu người dùng đã cài đặt Excel):
<%response.ContentType="application/vnd.ms-excel"%> <html> <body> <table> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> </tr> <tr> <td>5</td> <td>6</td> <td>7</td> <td>8</td> </tr> </table> </body> </html>