WebContextとは? わかりやすく解説

WebContext クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

現在の Web アプリケーションのパス コンテキストを管理します。このクラスは継承できません。

名前空間: System.Web.Configuration
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public NotInheritable Class
 WebContext
public sealed class WebContext
public final class WebContext
使用例使用例

WebContext クラスを使用する方法を次のコード例に示します。

Imports System
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

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();
    }
  }
}
継承階層継承階層
System.Object
  System.Web.Configuration.WebContext
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebContext メンバ
System.Web.Configuration 名前空間

WebContext コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

WebContext クラスの新しいインスタンスを作成します。

名前空間: System.Web.Configuration
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Sub New ( _
    pathLevel As WebApplicationLevel, _
    site As String, _
    applicationPath As String, _
    path As String, _
    locationSubPath As String _
)
Dim pathLevel As WebApplicationLevel
Dim site As String
Dim applicationPath As String
Dim path As String
Dim locationSubPath As String

Dim instance As New WebContext(pathLevel,
 site, applicationPath, path, locationSubPath)
public WebContext (
    WebApplicationLevel pathLevel,
    string site,
    string applicationPath,
    string path,
    string locationSubPath
)
public:
WebContext (
    WebApplicationLevel pathLevel, 
    String^ site, 
    String^ applicationPath, 
    String^ path, 
    String^ locationSubPath
)
public WebContext (
    WebApplicationLevel pathLevel, 
    String site, 
    String applicationPath, 
    String path, 
    String locationSubPath
)
public function WebContext (
    pathLevel : WebApplicationLevel, 
    site : String, 
    applicationPath : String, 
    path : String, 
    locationSubPath : String
)

パラメータ

pathLevel

WebApplicationLevel オブジェクト。

site

Web サイトの名前。

applicationPath

現在の Web アプリケーションのルート レベルへの仮想パス。

path

現在の構成オブジェクトが表している Web.config ファイルへの仮想パス。

locationSubPath

現在編集中の location 要素のパス値。

使用例使用例

WebContext コンストラクタを使用する方法を次のコード例に示します。このコード例は、WebContext クラスのトピックで取り上げているコード例の一部分です。

' Get the context.
Dim webContext As WebContext = config.EvaluationContext.HostingContext
// Get the context.
WebContext webContext = (WebContext)config.EvaluationContext.HostingContext;
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
WebContext クラス
WebContext メンバ
System.Web.Configuration 名前空間

WebContext プロパティ


WebContext メソッド


WebContext メンバ

現在の Web アプリケーションのパス コンテキストを管理します。このクラスは継承できません。

WebContext データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド WebContext WebContext クラスの新しいインスタンスを作成します。
パブリック プロパティパブリック プロパティ
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

WebContext クラス
System.Web.Configuration 名前空間



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「WebContext」の関連用語

WebContextのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



WebContextのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS