Atribut ContentType ASP

Panduan Rujukan Objek Response

Atribut ContentType menetapkan jenis konten HTTP bagi objek response.

Sintaks:

response.ContentType[=contenttype]
Parameter Deskripsi
contenttype

String untuk mendeskripsikan jenis konten.

Untuk daftar penuh jenis konten, silakan lihat dokumentasi pelayar Anda atau spesifikasi HTTP.

Contoh

Jika halaman ASP tidak menetapkan atribut ContentType, header content-type baku akan seperti ini:

content-type:text/html

Beberapa nilai ContentType yang biasa digunakan lainnya:

<%response.ContentType="text/HTML"%>
<%response.ContentType="image/GIF"%>
<%response.ContentType="image/JPEG"%>
<%response.ContentType="text/plain"%>
<%response.ContentType="image/JPEG"%>

Contoh ini akan membuka suatu table elektronik Excel di dalam pelayar (jika pengguna telah memasang 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>

Panduan Rujukan Objek Response