これが簡単なことはわかっていますが、名前が思い出せないので、方法を忘れてしまいました。解決策を探すのは困難でした。
C# でページ名を要求するにはどうすればよいですか?
例えば:
String pageName = String.Empty;
if(IsPost)
{
pageName = Request.PageName; // example only
}
.aspx ファイル名だけが必要な場合:
pageName = Page.Request.Url.Segments[Page.Request.Url.Segments.Length - 1];
http://www.dotnetperls.com/uriに、URI クラスを使用した良いサンプルがいくつかあり ます。
答えをより明確にするために
public string GetPageName()
{
string path = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo info = new System.IO.FileInfo(path);
return info.Name;
}
string pageName = Request.UrlReferrer != null ? System.IO.Path.GetFileName(Request.UrlReferrer.AbsolutePath) : Request.Url.Segments[Request.Url.Segments.Length - 1];
これはUrl
リライトでも使用できます。