IF statement in my SiteMaster.cs - determine current file name
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
}
精彩评论