ASP.NET Tutorial/Development/Context — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 14:56, 26 мая 2010
Содержание
Context.AddError
<source lang="csharp">
<%@ 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></source>
Context.GetConfig
<source lang="csharp">
<%@ 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) & "
") Next End Sub </script> </head>
<body>
<asp:label id="Message" runat="server"/>
</body> </html></source>
Context.IsCustomErrorEnabled
<source lang="csharp">
<%@ 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></source>
Context.IsDebuggingEnabled
<source lang="csharp">
<%@ 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></source>
Context.Items
<source lang="csharp">
<%@ 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></source>
Context.SkipAuthorization
<source lang="csharp">
<%@ 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></source>
Context.Timestamp
<source lang="csharp">
<%@ 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></source>
Context.Trace.IsEnabled
<source lang="csharp">
<%@ 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></source>
Context.User.Identity.Name
<source lang="csharp">
<%@ 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></source>