That is the part where the entire of the BODY element content is placed, You cannot tell the Script to get the Page for you. Somehow, you can use this trick.
var pageUrl = Request.Url;
This would get the URL for you in this format
[pageUrl: "http://localhost:xxxx/your_page"]
You can always extract the value for the your_page from the URL that you're having. That way you can get to know, which page is being utilized here.
Read more of my web development posts on my website. Thank you.
You can use System.IO.Path.GetFileName(Request.Url.ToString()). That will give you the file name that was requested but not the name of a the file used as RenderPage, or didn't you want that?
Member
405 Points
511 Posts
Finding a current page
Jul 09, 2014 06:24 AM|Chris17|LINK
Is there a way I can find the current page rendered by RenderBody() or RenderPage(). Thanks
Thanks for every help rendered.
ASP.Net Forum helped build me.
Contributor
4010 Points
1926 Posts
Re: Finding a current page
Jul 09, 2014 08:52 AM|Afzaal.Ahmad.Zeeshan|LINK
I am sorry, I was not able to understand your question but still, I think I would give you the Idea.
The RenderBody() is used to render the main code for the body element of the page that is using the Layout specified. Something like this
Then in the Layout file, you'll find this code.
That is the part where the entire of the BODY element content is placed, You cannot tell the Script to get the Page for you. Somehow, you can use this trick.
This would get the URL for you in this format
You can always extract the value for the your_page from the URL that you're having. That way you can get to know, which page is being utilized here.
All-Star
184748 Points
26712 Posts
Moderator
MVP
Re: Finding a current page
Jul 09, 2014 09:29 AM|Mikesdotnetting|LINK
You can use the VirtualPath property. The following will give you the current file's virtual path:
ASP.NET Tutorials | Learn Entity Framework Core| Learn Razor Pages
Member
405 Points
511 Posts
Re: Finding a current page
Jul 09, 2014 10:13 AM|Chris17|LINK
Ok. Please how do I extract that portion of the url so as to exclude the host name and folders
Thanks for every help rendered.
ASP.Net Forum helped build me.
All-Star
184748 Points
26712 Posts
Moderator
MVP
Re: Finding a current page
Jul 09, 2014 10:28 AM|Mikesdotnetting|LINK
You can use System.IO.Path.GetFileName(Request.Url.ToString()). That will give you the file name that was requested but not the name of a the file used as RenderPage, or didn't you want that?
ASP.NET Tutorials | Learn Entity Framework Core| Learn Razor Pages
Member
405 Points
511 Posts
Re: Finding a current page
Jul 09, 2014 10:56 AM|Chris17|LINK
Is there a way I can use it to get a parent folder?
Eg: http://localhost:xxxx/Customer/CustomerOrders
To Get the folder Customer
Thanks
Thanks for every help rendered.
ASP.Net Forum helped build me.
All-Star
184748 Points
26712 Posts
Moderator
MVP
Re: Finding a current page
Jul 09, 2014 03:19 PM|Mikesdotnetting|LINK
ASP.NET Tutorials | Learn Entity Framework Core| Learn Razor Pages