WebResourceAttribute.ContentType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得字串,包含 WebResourceAttribute 類別所參考之資源的 MIME 類型。
public:
property System::String ^ ContentType { System::String ^ get(); };
public string ContentType { get; }
member this.ContentType : string
Public ReadOnly Property ContentType As String
屬性值
資源的內容類型。
範例
下列程式碼範例示範如何查詢 屬性的值 ContentType 。
此程式碼範例是針對 類別提供的較大範例的 WebResourceAttribute 一部分。
<%@ Page Language="C#" %>
<%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.CS.Controls" Assembly="Samples.AspNet.CS.Controls" %>
<%@ Import Namespace="System.Reflection" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
// Get the assembly metatdata.
Type clsType = typeof(MyCustomControl);
Assembly a = clsType.Assembly;
// Iterate through the attributes for the assembly.
foreach (Attribute attr in Attribute.GetCustomAttributes(a))
{
//Check for WebResource attributes.
if (attr.GetType() == typeof(WebResourceAttribute))
{
WebResourceAttribute wra = (WebResourceAttribute)attr;
Response.Write("Resource in the assembly: " + wra.WebResource.ToString() +
" with ContentType = " + wra.ContentType.ToString() +
" and PerformsSubstitution = " + wra.PerformSubstitution.ToString() + "</br>");
}
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>WebResourceAttribute Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<AspNetSamples:MyCustomControl id="MyCustomControl1" runat="server">
</AspNetSamples:MyCustomControl>
</div>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<%@ Register TagPrefix="AspNetSamples" Namespace="Samples.AspNet.VB.Controls" Assembly="Samples.AspNet.VB.Controls" %>
<%@ Import Namespace="System.Reflection" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' Get the assembly metatdata.
Dim clsType As Type = GetType(MyCustomControl)
Dim a As Assembly = clsType.Assembly
For Each attr As Attribute In Attribute.GetCustomAttributes(a)
'Check for WebResource attributes.
If attr.GetType() Is GetType(WebResourceAttribute) Then
Dim wra As WebResourceAttribute = CType(attr, WebResourceAttribute)
Response.Write("Resource in the assembly: " & wra.WebResource.ToString() & _
" with ContentType = " & wra.ContentType.ToString() & _
" and PerformsSubstitution = " & wra.PerformSubstitution.ToString() & "</br>")
End If
Next attr
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>WebResourceAttribute Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<AspNetSamples:MyCustomControl id="MyCustomControl1" runat="server">
</AspNetSamples:MyCustomControl>
</div>
</form>
</body>
</html>
備註
內容類型的範例為 "image/jpeg"
和 "text/xml"
。 如需 MIME 類型的詳細資訊,請移至 網際網路指派號碼授權單位 網站,並參閱媒體類型一節。