Current PageID from CacheHelper

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
6/17/2008 4:35:24 AM
Gravatar
Total Posts 11

Current PageID from CacheHelper

Shouldn't this return the page id? :

PageSettings currentPage = CacheHelper.GetCurrentPage();
Pageid.Text = currentPage.PageID.ToString();

Or am I missing something here? I can't seem to find the variable PageID. However, this works:

                mojoSiteMapNode mojoNode = (mojoSiteMapNode)SiteMap.CurrentNode;
                LastModified.Text = mojoNode.Key.ToString();

But it's a ugly hack...

6/17/2008 6:03:49 AM
Gravatar
Total Posts 18439

Re: Current PageID from CacheHelper

This code should and does work:

PageSettings currentPage = CacheHelper.GetCurrentPage();
Pageid.Text = currentPage.PageId.ToString();

If you are working with your own custom pages outside the content system then you need to make sure you are passing the pageid of the current page in the query string because this determines what CurrentPage is used. Because of this, you can also generally get pageid with code like this:

int pageId = WebUtils.ParseIntFromQueryString("pageid", -1);

-1 here is the default value to return if pageid is not found in the query string params

If you fail to pass the pageid in the query string when navigating away from a content page to a custom page then CurrentPage will resolve to the first page in the site ,ie the home page.

Hope it helps,

Joe

6/17/2008 6:15:06 AM
Gravatar
Total Posts 11

Re: Current PageID from CacheHelper

I am inserting the ASP code in Layout.Master which works good, except for one occausion:

Default.aspx?pageid=0 works good, but Default.aspx (which are both the same content) does not execute the ASP code (but shows the right template). Is it possible to do a 301 redirect from Default.aspx to Default.aspx?pageid=0 if the pageid variable is not set? And if so, where would I put it..

6/17/2008 6:24:25 AM
Gravatar
Total Posts 18439

Re: Current PageID from CacheHelper

It shows the same content because it resolves the same. As I said if pageid is not passed CurrentPage will default to your first page which is in this case pageid 0. If it was not correctly resolving this you would not see the same content.

My advice is don't put any C# code directly in layout.master. Instead create a user control with your logic an add the user control to layout.master.

In your user control you can get page id like this:

int pageId = WebUtils.ParseIntFromQueryString("pageid", 0);

pass 0 in for the default if its not in the query string since that is your default page.

Still ,it should also work correctly from your user control using:

PageSettings currentPage = CacheHelper.GetCurrentPage();

then using currentPage.PageId.

If the code you have in layout.master is not executing under some circumstances I think there is something else going on to affect it. Try the user control approach.

Hope it helps,

Joe

You must sign in to post in the forums. This thread is closed to new posts.