views:

51

answers:

1

By convention, all my web site's .aspx files also have corresponding .css files at the same path. So, for example, Default.aspx has a file Default.css in the same directory.

I wrote an extension method to add CSS tags to the headers of Page objects, and use it like this on Page_Load:

this.AddCssFileRange(new[]
{
    "Default.css",
    "../Master.css"
});

I'd like to replace the hardcoded "Default.css" with a method that derives this based on my CSS convention. That is, I'd like to replace it with a method that returns "Default.css" because the filename of the Page calling it is "Default.aspx."

How can I retrieve that "Default.aspx" filename so I can replace the extension with "css"?

+1  A: 

Like this: Path.ChangeExtension(Request.CurrentExecutionFilePath, ".css").
This will return the currently executing page, even if you called Server.Transfer.

SLaks