WebContext Kelas
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Mengelola konteks jalur untuk aplikasi Web saat ini. Kelas ini tidak dapat diwariskan.
public ref class WebContext sealed
public sealed class WebContext
type WebContext = class
Public NotInheritable Class WebContext
- Warisan
-
WebContext
Contoh
Contoh berikut menunjukkan cara menggunakan WebContext kelas .
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
Konstruktor
| Nama | Deskripsi |
|---|---|
| WebContext(WebApplicationLevel, String, String, String, String, String) |
Menginisialisasi instans baru dari kelas WebContext. |
Properti
| Nama | Deskripsi |
|---|---|
| ApplicationLevel |
WebApplicationLevel Mendapatkan objek yang mewakili tingkat jalur aplikasi Web saat ini. |
| ApplicationPath |
Mendapatkan jalur aplikasi dari aplikasi Web saat ini. |
| LocationSubPath |
Mendapatkan subpath lokasi aplikasi Web. |
| Path |
Mendapatkan jalur virtual aplikasi Web saat ini. |
| Site |
Mendapatkan nama aplikasi Web saat ini. |
Metode
| Nama | Deskripsi |
|---|---|
| Equals(Object) |
Menentukan apakah objek yang ditentukan sama dengan objek saat ini. (Diperoleh dari Object) |
| GetHashCode() |
Berfungsi sebagai fungsi hash default. (Diperoleh dari Object) |
| GetType() |
Mendapatkan Type instans saat ini. (Diperoleh dari Object) |
| MemberwiseClone() |
Membuat salinan dangkal dari Objectsaat ini. (Diperoleh dari Object) |
| ToString() |
Mengembalikan string yang mewakili jalur konfigurasi aplikasi. |