3

これが簡単なことはわかっていますが、名前が思い出せないので、方法を忘れてしまいました。解決策を探すのは困難でした。

C# でページ名を要求するにはどうすればよいですか?

例えば:

String pageName = String.Empty;
if(IsPost)
{
   pageName = Request.PageName; // example only
}
4

3 に答える 3

2

.aspx ファイル名だけが必要な場合:

pageName = Page.Request.Url.Segments[Page.Request.Url.Segments.Length - 1];

http://www.dotnetperls.com/uriに、URI クラスを使用した良いサンプルがいくつかあり ます。

于 2013-05-15T01:18:53.623 に答える
1

答えをより明確にするために

public string GetPageName() 
{ 
    string path = System.Web.HttpContext.Current.Request.Url.AbsolutePath; 
    System.IO.FileInfo info = new System.IO.FileInfo(path); 
    return info.Name; 
}
于 2013-05-15T01:15:23.533 に答える
0
string pageName = Request.UrlReferrer != null ? System.IO.Path.GetFileName(Request.UrlReferrer.AbsolutePath) : Request.Url.Segments[Request.Url.Segments.Length - 1];

これはUrlリライトでも使用できます。

于 2015-04-12T10:48:58.753 に答える