I need to find out name of location where web user control is. Somethnig like HttpContext.Current.Request.Url.ToString(), but I get only page for this web user control.
我需要找出Web用户控件所在的位置名称。 Somethnig喜欢HttpContext.Current.Request.Url.ToString(),但我只获得此Web用户控件的页面。
5 个解决方案
#1
12
Request.Url.Segments will give you a string array. The last item is the page
Request.Url.Segments将为您提供一个字符串数组。最后一项是页面
#2
2
You should try the Request.Url.LocalPath
property
您应该尝试Request.Url.LocalPath属性
string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath);
#3
1
This code helps:
此代码有助于:
string filename = Path.GetFileName(Request.Url.AbsolutePath);
#4
0
You can also use (VB.Net):
你也可以使用(VB.Net):
Dim pageName as String = Page.GetType().Name
which replaces the .extension with an underscore
用。下划线替换.extension
So from Default.aspx you would be returned Default_aspx
因此,从Default.aspx您将返回Default_aspx
You can also use:
您还可以使用:
Dim pageName as String = CType(HttpContext.Current.CurrentHandler, Page).GetType().Name
Which will produce the same results as described above.
这将产生与上述相同的结果。
#5
0
If you ask for Page.getType.name, you will get the name of the master, the aspx page. if you want the name of the ascx control you are working on, use me.GetType.Name.ToString if your control is in a directory MyDir and the name of your ascx is test.ascx then the result will be
如果您要求Page.getType.name,您将获得master的名称,即aspx页面。如果你想要你正在使用的ascx控件的名称,请使用me.GetType.Name.ToString如果你的控件在一个目录MyDir中,你的ascx的名字是test.ascx那么结果将是
"ASP.MyDir_test_ascx"
#1
12
Request.Url.Segments will give you a string array. The last item is the page
Request.Url.Segments将为您提供一个字符串数组。最后一项是页面
#2
2
You should try the Request.Url.LocalPath
property
您应该尝试Request.Url.LocalPath属性
string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath);
#3
1
This code helps:
此代码有助于:
string filename = Path.GetFileName(Request.Url.AbsolutePath);
#4
0
You can also use (VB.Net):
你也可以使用(VB.Net):
Dim pageName as String = Page.GetType().Name
which replaces the .extension with an underscore
用。下划线替换.extension
So from Default.aspx you would be returned Default_aspx
因此,从Default.aspx您将返回Default_aspx
You can also use:
您还可以使用:
Dim pageName as String = CType(HttpContext.Current.CurrentHandler, Page).GetType().Name
Which will produce the same results as described above.
这将产生与上述相同的结果。
#5
0
If you ask for Page.getType.name, you will get the name of the master, the aspx page. if you want the name of the ascx control you are working on, use me.GetType.Name.ToString if your control is in a directory MyDir and the name of your ascx is test.ascx then the result will be
如果您要求Page.getType.name,您将获得master的名称,即aspx页面。如果你想要你正在使用的ascx控件的名称,请使用me.GetType.Name.ToString如果你的控件在一个目录MyDir中,你的ascx的名字是test.ascx那么结果将是
"ASP.MyDir_test_ascx"