开发者

IF statement in my SiteMaster.cs - determine current file name

开发者 https://www.devze.com 2023-03-07 01:15 出处:网络
In my SiteMaster.cs file I am using the following query to retrieve data from my database: 开发者_运维知识库

In my SiteMaster.cs file I am using the following query to retrieve data from my database:

开发者_运维知识库

SqlCommand comm = new SqlCommand("SELECT ID, Title, Name, Keywords, Descr FROM pages WHERE ID=1", conn);

I would like to do the following:

a) determine the current page & b) use this page to set a pageID variable equal to a certain number.

So if I was on (say) Default.aspx I could do something like...

// determine file name // if (file name == 'default.aspx') { pageID = 1; }

Would love some help with this.

Many thanks!!


You can do this to get the current aspx filename:

string pagePath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo pageFile = new System.IO.FileInfo(pagePath);
string pageName= pageFile.Name;


String pageName  = Request.FilePath;

//return like that /example.aspx

if (pageName == "/default.aspx") 
{
// your code
}
0

精彩评论

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