Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method to retrieve the file name of a class?

Tags:

c#

asp.net

Is there a method to retrieve the file name of a class?

Specifically I would like to create a static method (CreateLink) in a base class (BasePage) to automatically return the path and filename of the page called.

I code in .C# ASP.NET

private const string TEMPLATE =
    "~/One.aspx";

public static HyperLink CreateLink()
{
    HyperLink link = new HyperLink();
    link.Text = "Click here";
    link.NavigateUrl = String.Format(TEMPLATE);
    return link;
}

Is it possible to avoid the use of TEMPLATE hardcoded variable? Is it possible to retrieve the One.aspx path from file name and location?

like image 724
Bastien Vandamme Avatar asked Jan 21 '23 22:01

Bastien Vandamme


1 Answers

You can get the path of the page currently request by checking HttpContext.Current.Request.Path.

like image 80
SLaks Avatar answered Jan 24 '23 12:01

SLaks