ASP.NET - current page name from web user control?

I need to find out the name of the location where the web user control is located. Somethnig is like HttpContext.Current.Request.Url.ToString (), but I only get the page for this web user.

+6
source share
5 answers

Request.Url.Segments will provide you with a string array. The last item is the page

+12
source

You should try the Request.Url.LocalPath property

 string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath); 
+2
source

This code helps:

 string filename = Path.GetFileName(Request.Url.AbsolutePath); 
+1
source

You can also use (VB.Net):

 Dim pageName as String = Page.GetType().Name 

which replaces the underlined extension

So, from Default.aspx you will be returned Default_aspx

You can also use:

 Dim pageName as String = CType(HttpContext.Current.CurrentHandler, Page).GetType().Name 

which will give the same results as described above.

0
source

If you ask for the name Page.getType.name, you will get the name of the aspx homepage. if you want the name of the ascx control to work, use me.GetType.Name.ToString if your control is in the MyDir directory and your ascx is test.ascx, then the result will be

"ASP.MyDir_test_ascx"

0
source

Source: https://habr.com/ru/post/888990/


All Articles