How to get aliased name of page in master page code behind?

I'd like to access the aliased name generated by the CMS of a page for some logic. Using

Request.Path.Substring(Request.Path.LastIndexOf("/") + 1)

in the master page code behind only gets me the master page name.


If that isn't possible, is there something else I can reference that would uniquely identify a particular page from the master page code behind?

 


Tobias
Using VS 2005, C#. Learning on the fly.
0
Temgee
3/26/2009 8:43:45 PM
asp.net.navigation-controls 13714 articles. 0 followers. Follow

5 Replies
628 Views

Similar Articles

[PageSpeed] 29

Hi Temgee,

Try refer this code,

    protected void Page_Load(object sender, EventArgs e)
    {
       Response.Write(System.Web.HttpContext.Current.Request.Url.AbsolutePath.ToString());
    }
 
Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
3/31/2009 7:31:29 AM

 Unfortunately that also displays the template name and not the alias name.

 I get the same thing whether the code is on the master page or template page code behind.


Tobias
Using VS 2005, C#. Learning on the fly.
0
Temgee
4/1/2009 7:57:18 PM

Sorry, I can not reproduce this issure, please try to post a workable code here for us checking, thanks.


Hong-Gang Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Hong
4/2/2009 3:25:01 AM

 The alias is generated by the CMS that uses the template. I don't actually have code built to generate the alias. I can see if I can dig out the code from the CMS that handles the aliasing if that's any help.

 In the meantime I'm just going to build a second template to circumvent the problem.


Tobias
Using VS 2005, C#. Learning on the fly.
0
Temgee
4/2/2009 6:31:04 PM

 Asking me about the code prompted me to dig around in the CMS a bit, and it turns out there is an API for the aliasing.

 So with a reference to that on the template code behind I ended up with this which does the trick:

 UrlAliasCommon alias = new UrlAliasCommon();
      if (alias.GetAliasForContent(Convert.ToInt32(Request.QueryString["id"])).Substring(alias.GetAliasForContent(Convert.ToInt32(Request.QueryString["id"])).LastIndexOf("/") + 1) == "welcome.aspx")


Tobias
Using VS 2005, C#. Learning on the fly.
0
Temgee
4/2/2009 8:29:54 PM
Reply:

Similar Artilces:

How can I access the property a control on a master page from the master page's code behind.
On my master page I have a label. I want to change this label's text property based on an element of the querystring. (label.text = "NewValue")All child pages using this master will display the same thing so I was trying to put the code in the master page so as not to have to duplicate it for the child pages or put it in a base class and use FindControl.Is it possible to access from a master page's codebehind the property of a server control that is placed on a master page's aspx? If so how?(I saw similar questions, but they all came from the view of a child accessing the property.)Thank you...

How do you get a reference to the Master page from the code behind of the content page? PLEASE HELP!
Man, I have been messing with this for days. I need to set a string in the Master page from the content page. I can get a reference to the master page SOMETIMES.... and then other, seemingly random (though weighted at 99%) times I can't!!! I have changed the reference manually in the .aspx file, I have experimented with nested master pages and subdirectories, ...I've done everything I can think of several times but intellisense never picks it up and it always gets a red squiggly line. The only time it does seem to work MOST of the time is if both the master page and content page are...

Master Page Code Behind
I want to create a base class for the code behind my master pages. The base class should override the Page_Load method of each Master Page. The idea behind this is to have each Master Page include the custom cascading stylesheet that will style the layout contained in the master page. For example, SplitPane.master should automatcially apply the CSS file named SplitPane.css. Furthermore, SplitPane.master is a master page nested in another master page named Default.master that should apply the CSS file Default.css. The base class should be applied to each master page, so that I need to copy ...

setting a controls properties within a master page from aspx page without code behind
I have a custom header control that has a public property TabID declared in the codebehind of the control itself. In asp1.1, I dragged the header control to a page and set the tabid like: <uc1:myheader runat="server" TabID="1" /> inside the aspx page it was placed. Now I would like to put the header control inside a master page, but I'm not sure how to set this property without setting it in codebehind for every page i create.  Is this possible? What is the best way to get this value to the header control as it is different for every page?...

Code Behind Pages with Master Pages
I want to make one code-behind page with all the functions and procedures and then use this from both the master and content pages. What does the syntax look like for the code-behind page, and what do I have to put in the master and contentpages to access those functions?...

Getting the name of the child or calling page from the .master.cs code behind
Does anyone know how to get the name/path of the child page.  The problem is that I've got a master page called global.master, and serveral (child) pages that use it.  One child page, needs a js script in order to function property, and that script needs to be at the very bottom of the rendered page, (i.e. just before the <body/> tag of the master).  The other child pages won't function properly if that js is included.  So, if I can detect from the .master.cs when that particular child pages is calling, I can include the.js for it alone and all is well.  Any id...

Content controls have to be top-level controls in a content page or a nested master page that references a master page.
Why in the world am I getting this error? The solutions I have seen either don't apply or don't work.  Here is my master page code:<%@ Master Language="C#" AutoEventWireup="false" CodeFile="TechLMSMasters/MainSide.master.cs" Inherits="MainSide" %> <%@ Register TagPrefix="usercontrol" TagName="Search" Src="~/library/uc/Search.ascx" %> <%@ Register TagPrefix="usercontrol" TagName="UserName" Src="~/library/uc/UserNameDisplay.ascx" %><!DOCTYPE html PUBLI...

Help requested to connect a TreeView control existing on a Master page to an existing aspx/code behind page.
Help requested to connect a TreeView control existing on a Master page to an existing aspx/code behind page. I have defined a working master page which contains a TreeView control and a ContentPlaceHolder.  The tree control displays as follows:  Agriculture Undergrad  (Program node) Business Undergrad   Health Undergrad   Industrial Undergrad   Service Undergrad   Technical Undergrad      Arboriculture-Urban Forestry  (Plan sub node)    Paper & Chemical Technology     ...

Error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.
when I make a directory on my root, and in that directory I put a masterpage and a web form ... I get always an error : Content controls have to be top-level controls in a content page or a nested master page that references a master page.   Does somebody know what the problem is ? Is it possible you can't set a masterpage in a directory ... ?Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) i've founded ... I had to nest my masterpage ...Kind Regards,Joeri Pansaerts.From Bruges, Belgium :) Hi Joeri Pansaerts, I am receiving the same error as the one posted her...

ERROR Content controls have to be top-level controls in a content page or a nested master page that references a master page.
This all used to work until about 5 minutes ago. Did I change something? For some reason I am now getting this error: Content controls have to be top-level controls in a content page or a nested master page that references a master page. What I have:  I have a masterpage inside of a directory. That directory is a first level directory with its own web.config file....The whole thing is protected by the web.config file above it (in the main public directory). That main public directory has a masterpage as well. I am not currently linking the two masterpages together becuase...

Obtain instance of Main.master from within User Control code behind when user control is referenced from a nested master page
I have a user control that's being referenced from within a nested master page.  I need to FROM WITHING THE USER CONTROL itself (not the other way around, not Master to user control) access a control in the master page because I need to set it's ImageURL.The setup is like this:Main.master (holds a Menu control called Menu1)        Admin.master (inherits Main.master)                   myusercontrol.ascx (is referenced in Admin.master) I cannot figure out how to get an instance to Main.master from within my...

How to get a handle on a user control from the code behind of the page holding the control?
I have a .aspx page that uses a .ascx page. So a web form with a server control(.ascx) on it. Basically the control has about four drop down listboxes on it. Lets call them ddlOne, ddlTwo, etc. My question, is how do I access the drop down listbox in the C# code behind file for my web form?(.aspx) So for example how would I access ddlOne which is the drop down listbox on the user/server control? Please help? You could expose them as read-only properties of the usercontrol.  In the codebehind of the usercontrol, you could add: Public ReadOnly Property DDL1() As DropDownList ...

How to make use of master page class name in the page which is making use of master page
Hi All, Suppose page 1 makes use of one  master page say master1 How to make use of master page class name in page1.   Thanks and regards Abdul  You can use the masterpage class by adding a refference of the master page in the aspx. You can add the reference directly in the page tag or use a <%@ MasterType %> tage to refer the master page typeVikram www.vikramlakhotia.comPlease mark the answer if it helped you Hi, abdulmg:How to make use of master page class name in page1. You can try to do like below: YourMasterPagesClassName master = (YourMasterPagesClassN...

HELP..... Master Page Error (The page has controls that require a Master Page, but none is specified.)
Hi, I had almost finished creting my master page to use as a template for all future internal applications.  I had created a template to use in creatign new applications and had sucessfully created a new project based upon the MasterPage template... All was working well when I noticed a small graphic inconsistancy on the MasterPage... I reopened the MasterPage and I got teh above error message... I have looked at the HTML and everything seems to be okay and there including the header lines... <%@ Master Language="VB" CodeFile="MasterPage.master.vb" Inherits=&qu...

Web resources about - How to get aliased name of page in master page code behind? - asp.net.navigation-controls

Handle findAllRefs/getOccurrences for properties inherited from aliased types by DanielRosenwasser · ...
Skip to content Ignore Learn more Please note that GitHub no longer supports Internet Explorer versions 7 or 8. We recommend upgrading to the ...

Anti-aliased Articles on TUAW - The Unofficial Apple Weblog
Anti-aliased articles, stories, news and information.

Resources last updated: 12/11/2015 5:51:35 PM