开发者

ASP.NET: Getting ASPX filename

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.AddC开发者_如何学GossFileRange(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"?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜