ASP.NET Tutorial/Development/Context — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 26 мая 2010

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>