ASP.NET Tutorial/Development/Context
Содержание
Context.AddError
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Try
Context.AddError(New Exception("Test"))
Finally
Message.Text = "Context.Error.ToString() is " & _
Context.Error.ToString()
Context.ClearError()
End Try
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.GetConfig
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Dim i As Integer
Dim nv As NameValueCollection
nv = Context.GetConfig("appSettings")
For i = 0 To nv.Count - 1
Response.Write(nv.GetKey(i) & " = " & nv(i) & "<br/>")
Next
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.IsCustomErrorEnabled
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Message.Text = "Custom Error Enabled? " & Context.IsCustomErrorEnabled
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.IsDebuggingEnabled
<%@ Page Language="vb" debug="false" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Message.Text = "Debugging Enabled? " & Context.IsDebuggingEnabled
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.Items
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Context.Items("Foo")="Bar"
Context.Items.Add("Bar","Foo")
Message.Text = "Context.Items.Contains(""Foo"") is " & _
Context.Items.Contains("Foo")
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.SkipAuthorization
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Message.Text = "SkipAuthorization? " & Context.SkipAuthorization
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.Timestamp
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Message.Text = "Date/Time of Request: " _
& Context.Timestamp
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.Trace.IsEnabled
<%@ Page Language="vb" Trace="True" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Message.Text = "Trace Enabled? " _
& Context.Trace.IsEnabled
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Context.User.Identity.Name
<%@ Page Language="vb" %>
<html>
<head>
<title>Context property example</title>
<script runat="server">
Sub Page_Load()
Message.Text = "Currently logged in as: " & _
Context.User.Identity.Name
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>