ASP.NET Tutorial/Development/Context

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

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>