WebContext Klass
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Hanterar sökvägskontexten för det aktuella webbprogrammet. Det går inte att ärva den här klassen.
public ref class WebContext sealed
public sealed class WebContext
type WebContext = class
Public NotInheritable Class WebContext
- Arv
-
WebContext
Exempel
Följande exempel visar hur du använder WebContext-klassen.
using System;
using System.Configuration;
using System.Web;
using System.Web.Configuration;
namespace WebContextTest01cs
{
class UsingWebContext
{
static void Main(string[] args)
{
try
{
// Set the path of the config file.
string configPath = "/aspnet";
// Get the Web application configuration object.
Configuration config =
WebConfigurationManager.OpenWebConfiguration(configPath);
// Get the context.
WebContext webContext = (WebContext)config.EvaluationContext.HostingContext;
// Display title.
Console.WriteLine("ASP.NET WebContext Info");
Console.WriteLine("");
// WebContext - Application Level.
Console.WriteLine("ApplicationLevel: {0}",
webContext.ApplicationLevel.ToString());
// WebContext - Application Path.
Console.WriteLine("ApplicationPath: {0}",
webContext.ApplicationPath.ToString());
// WebContext - Path.
Console.WriteLine("Path: {0}", webContext.Path.ToString());
// WebContext - Site.
Console.WriteLine("Site: {0}", webContext.Site.ToString());
}
catch (Exception ex)
{
// Unknown error.
Console.WriteLine(ex.ToString());
}
// Display and wait.
Console.ReadLine();
}
}
}
Imports System.Configuration
Imports System.Web
Imports System.Web.Configuration
Namespace Samples.Aspnet.SystemWebConfiguration
Class UsingWebContext
Public Shared Sub Main()
Try
' Set the path of the config file.
Dim configPath As String = "/aspnet"
' Get the Web application configuration object.
Dim config As Configuration = _
WebConfigurationManager.OpenWebConfiguration(configPath)
' Get the context.
Dim webContext As WebContext = config.EvaluationContext.HostingContext
' Display title and info.
Console.WriteLine("ASP.NET WebContext Info")
Console.WriteLine()
' WebContext - Application Level.
Console.WriteLine("ApplicationLevel: {0}", _
webContext.ApplicationLevel.ToString())
' WebContext - Application Path.
Console.WriteLine("ApplicationPath: {0}", _
webContext.ApplicationPath.ToString())
' WebContext - Path.
Console.WriteLine("Path: {0}", webContext.Path.ToString())
' WebContext - Site.
Console.WriteLine("Site: {0}", webContext.Site.ToString())
Catch e As Exception
' Unknown error.
Console.WriteLine(e.ToString())
End Try
' Display and wait
Console.ReadLine()
End Sub
End Class
End Namespace
Konstruktorer
| Name | Description |
|---|---|
| WebContext(WebApplicationLevel, String, String, String, String, String) |
Initierar en ny instans av WebContext klassen. |
Egenskaper
| Name | Description |
|---|---|
| ApplicationLevel |
Hämtar ett WebApplicationLevel objekt som representerar sökvägsnivån för det aktuella webbprogrammet. |
| ApplicationPath |
Hämtar programsökvägen för det aktuella webbprogrammet. |
| LocationSubPath |
Hämtar platsundersökvägen för webbprogrammet. |
| Path |
Hämtar den aktuella virtuella sökvägen för webbprogrammet. |
| Site |
Hämtar namnet på det aktuella webbprogrammet. |
Metoder
| Name | Description |
|---|---|
| Equals(Object) |
Avgör om det angivna objektet är lika med det aktuella objektet. (Ärvd från Object) |
| GetHashCode() |
Fungerar som standard-hash-funktion. (Ärvd från Object) |
| GetType() |
Hämtar den aktuella instansen Type . (Ärvd från Object) |
| MemberwiseClone() |
Skapar en ytlig kopia av den aktuella Object. (Ärvd från Object) |
| ToString() |
Returnerar en sträng som representerar programmets konfigurationssökväg. |