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.
Request.Url.Segments will give you a string array. The last item is the page
You should try the Request.Url.LocalPath
property
string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath);
This code helps:
string filename = Path.GetFileName(Request.Url.AbsolutePath);
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
"ASP.MyDir_test_ascx"
You can also use (VB.Net):
Dim pageName as String = Page.GetType().Name
which replaces the .extension with an underscore
So from Default.aspx you would be returned 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.
精彩评论