开发者

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
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜