ASP.Net/Session Cookie/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.Error
<%@ 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>
<%--
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="foo" value="bar"/>
<add key="foo2" value="bar2"/>
</appSettings>
</configuration>
--%>
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.Items.Contains
<%@ 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.IsAuthenticated
<%@ Page Language="vb" %>
<html>
<head>
<script runat="server">
Sub Page_Load()
Message.Text = "User.Identity.IsAuthenticated? " _
& Context.User.Identity.IsAuthenticated & "<br/>"
If Context.User.Identity.IsAuthenticated then
Message.Text = Message.Text & "User.Identity.Name? " _
& Context.User.Identity.Name & "<br/>"
end if
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>