Page view counter

PROBLEM USING MASTER PAGE IN SUBFOLDERS

Last post 04-09-2009 7:10 PM by sonic20x. 20 replies.

Sort Posts:

  • PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-12-2008, 5:02 AM
    • Loading...
    • anty.panty
    • Joined on 01-25-2008, 10:09 AM
    • Posts 3
    • Points 0

     i am having problems using masterpages in subfolders. anything in the general folder i easily link to the masterpage and it works, but when i put it in to website/folder/file.aspx it won't link properly. PLEASE HELP ME!!!!!!!!!!!!!!!!

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-12-2008, 8:39 AM
    • Loading...
    • Adam.Kahtava
    • Joined on 10-18-2006, 2:14 PM
    • Canada
    • Posts 926
    • Points 4,753

    How are you referencing your master page? Is it referenced through the web.config? Is it referenced through the .aspx page? Check that you are NOT using relative paths like "../../MasterPage", instead use the web application root operator "~/MasterPage".

    A link that may be of interest: ASP.NET Web Site Paths

  • Re:RE: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-13-2008, 7:48 PM
    • Loading...
    • anty.panty
    • Joined on 01-25-2008, 10:09 AM
    • Posts 3
    • Points 0

     hi its me again, i am referencing ~/master.master through file.aspx but it still don't work

  • Nested Master Pages on a Virtual Subdirectory - Compiler reference resolution incorrect?

    02-13-2008, 8:21 PM
    • Loading...
    • ylDave
    • Joined on 02-14-2008, 1:16 AM
    • Posts 3
    • Points 6
    I think I may have a similar issue to the original poster. 

    In IIS 5.1 I have setup a virtual directory and made one of the subfolders an application:

    http://localhost/wh4l/Default.aspx

    http://localhost/wh4l/SomeApp/Default.aspx

    In the subfolder, I am using nested master pages; the parent does not need master pages.

    I find I need to have duplicate copies of the master pages in the parent folder for the site to compile in Visual Studio 2008.

    If I delete the Master pages off the parent, I get a compile error in the Default.aspx page in the subfolder referencing a master page:

    Error 4 The file '/wh4l/MasterPages/SpecificLayout.master' does not exist. C:\...\WebSites\wh4l\SomeApp\Default.aspx 1 

    The compiler is referencing master pages off the parent rather than the subfolder.

     

    If I delete the master pages from the subfolder, the solution compiles but I get a runtime error when I access the Default.aspx page on the subfolder that is referencing the master files:

    Parser Error Message: The file '/wh4l/SomeApp/MasterPages/SpecificLayout.master' does not exist.

     

    The master file is being referenced from the Default.aspx on the subfolder as a relative reference:

    <%@ Page Language="C#" MasterPageFile="~/MasterPages/SpecificLayout.master" ...

     

    The compiler prevents me from referencing the master pages on the parent folder:

    <%@ Master Language="C#" MasterPageFile="/MasterPages/SpecificLayout.master"

    Error 7 The virtual path '/MasterPages/SpecificLayout.master' maps to another application, which is not allowed. C:\...\WebSites\wh4l\SomeApp\Default.aspx 1 

    It seems that IIS is resolving master page references differently than the compiler; compiler resolution of master page references appears to be incorrect.

    Is there a way to change the reference or the configuration so the compiler uses the correct master pages?

     

    Dave

  • Re: Nested Master Pages on a Virtual Subdirectory - Compiler reference resolution incorrect?

    02-14-2008, 5:20 AM
    • Loading...
    • Johnson2007
    • Joined on 05-17-2007, 7:19 AM
    • Posts 449
    • Points 2,273

    Hi,

    How the files and the folders are placed in your Visual Studio 2008 and IIS? I mean do you place the masterpage in the root folder of the application(VS2008)? Is the "/MasterPages/" is the website name or a subfolder's name? In the IIS, is the masterpage placed under the vitualPage folder or in the root of your App? If you can illustrate it using a fig. it will be very grate. Thank you. 

    Johnson
  • Re: Nested Master Pages on a Virtual Subdirectory - Compiler reference resolution incorrect?

    02-14-2008, 11:55 AM
    • Loading...
    • ylDave
    • Joined on 02-14-2008, 1:16 AM
    • Posts 3
    • Points 6

    Both the root folder of the application (wh4l) and a subfolder (SomeApp) are designated as applications in IIS:

    C:\...\Visual Studio 2008\WebSites\wh4l\SomeApp

     I have identical sets of master pages in 2 locations; regular subdirectories off of the designated application directories:

    C:\...\Visual Studio 2008\WebSites\wh4l\MasterPages

    C:\...\Visual Studio 2008\WebSites\wh4l\SomeApp\MasterPages

     Thanks

  • Re: Nested Master Pages on a Virtual Subdirectory - Compiler reference resolution incorrect?

    02-14-2008, 4:37 PM
    • Loading...
    • happyfirst
    • Joined on 01-24-2008, 8:04 PM
    • Posts 54
    • Points 16

    I'm having a similar issue that I posted there: http://forums.asp.net/t/1219593.aspx

    I'm using IIS and virtual directories but my sub directories are NOT IIS applications. I've got

    \webapp\   [IIS virtual directory pointing to my root web application project and also an IIS Application]

    \webapp\core\ [IIS virtual directory pointing to my core module web application project. NOT an IIS Application]

    Now I have my default core master page templates in \webapp\core\templates project and the MasterPageFile setting is "~/Templates/Main.Master". I can open the content page in VS 2008 and it's editable. I can NOT run the application however unless I also copy Main.Master to /webapp/templates/.

    So it seems at design time, VS is correctly resolving ~ relative to it's project and iis directory. At runtime, IIS is always resolving ~ to the root application.

    Furthermore, at runtime, it looks like .net is trying to validate that whatever MasterPageFile is set in the aspx page is a valid existing master page. All before the PreInit event where I'm going to change that setting anyways.

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-16-2008, 12:15 AM
    • Loading...
    • Strupi
    • Joined on 02-10-2008, 2:59 AM
    • Sacramento, CA
    • Posts 8
    • Points 56

     Hi,

    I am not sure that I understand your problem.  A common problem is when a masterpage is in the root folder and you try to use it from an aspx page in a subfolder.  In such a case, all the links on the masterpage will fail unless they are run on the server.  So they have to be converted from HTML code to server controls.  Here is how that is done.

    TO FIX LINK TO STYLES IN A STYLES FOLDER
    Simply add the runat="server" property to the <head> tag

    Example:

    <head runat="server">

    <link href="styles/MyStyleSheet.css" rel="stylesheet" type="text/css" />

    </head>


    TO FIX IMAGES:
    Use the <asp:Image tag.

    Example:

    <asp:image Id="Image13"  runat="server" ImageUrl="~/images/walkingholidays.jpg" alternateText="Walking Holidays" width="192" height="77" borderwidth="0" />

    NOTE: Look very closly at ALL the wording.  You need the ID=, runat="server", ImageUrl =, the tilde (~) before the path and the alt property must be spelled out (AlternateText=) and border is now "borderwidth."  Any departure from this wording will screw you up. To find out more about this tag, go to the help menu in VWD and search for <asp:image in the index.

    TO FIX ANCHOR TAGS:
    Add an Id= property and the runat="server" property. Note that there is no tilde (~) before the path as there is in the above image example.

    Example:

    <a Id="A1"  href = "Pages/Calendar.aspx" runat="server">CALENDAR</a>

    All of these examples assume that the MasterPage is in the root directory.

    Jim Webber, Sacramento



    Jim Webber, Sacramento, California
  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-17-2008, 9:30 PM
    • Loading...
    • happyfirst
    • Joined on 01-24-2008, 8:04 PM
    • Posts 54
    • Points 16

    This issue is NOT about a problem with the hyperlinks in the pages. They all work properly as long as they are server controls as you stated. The designer will show them in error that they don't exist though because I am including the module subdirectory in the path.

    I have a web application project hosted via IIS virtual directory and application at localhost\mainsite\.

    I also have a module that's ANOTHER web application project hosted as IIS virtual directory ( but NOT application ) at localhost\mainsite\core.

    ALL of my user controls and pages are in core. Their hyperlinks work just fine whether I grab the master page template from locahost\mainsite\templates OR localhost\mainsite\core\templates.  If I leave the MasterPageFile setting in my core pages as ~/templates/pages/main.master then I can edit the page in the designer and VS resolves ~ to the virtual directory for the core1 directory. When I RUN the app however, .net runtime is resolving ~ to the mainsite directory so I have to have my templates ALSO in locahost\mainsite\templates or .net throws an exception about the templates missing. The problem is this is WRONG as I'm going to switch the template in PreInit but the code doesn't get that far. It's verifying the MasterPageFile setting stored in the aspx page. Personally, I think that I should be setting my MasterPageFile setting to ~/core/templates/pages/main.master in my core aspx pages. But I can't since VS resolves ~ differently than at runtime.

    So I basically have to remove the MasterPageFile setting from the aspx pages so that I can truly choose where I want to load the masterpagefile from at runtime. But then I loose designer editting.

    There are basically two bugs here.

    1) .net should not verify that the masterpagefile exists UNTIL AFTER preinit.

    2) What should '~' resolve to for a nested website application project. I think VS is doing the wrong thing. ~ should resolve to localhost\mainsite in the core project. It should not include the core directory in the path since it's not an application. If anything, VS project settings should allow us to override what ~ resolves to at designtime.

     

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-17-2008, 10:17 PM
    • Loading...
    • Strupi
    • Joined on 02-10-2008, 2:59 AM
    • Sacramento, CA
    • Posts 8
    • Points 56

     Reply to HappyFirst:

    I was responding to Anty.Panty's problem at the top of this page.  You have a different problem and need to post a new thread to get a response.  To do that, click on the Master Pages, Themes and Navigation Controls in the breadcrumb at the top of this page. That will take you to a page where you can post a new question.  Wink

    Jim Webber, Sacramento, California
  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-17-2008, 11:59 PM
    • Loading...
    • ylDave
    • Joined on 02-14-2008, 1:16 AM
    • Posts 3
    • Points 6

    Good writeup happyfirst.  That is the same issue I'm seeing - the discrepancy between how master page file paths are getting resolved at runtime and at design time; probably a question / bug for Microsoft.  It is unclear whether it is the same issue for antsy pants since we don't have enough info on how his references are set up.  I'll post elsewhere and see if I can find an answer. 

    Dave

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-18-2008, 8:27 AM
    • Loading...
    • happyfirst
    • Joined on 01-24-2008, 8:04 PM
    • Posts 54
    • Points 16

    Strupi:

    I was responding to Anty.Panty's problem at the top of this page.  You have a different problem and need to post a new thread to get a response.  To do that, click on the Master Pages, Themes and Navigation Controls in the breadcrumb at the top of this page. That will take you to a page where you can post a new question.  Wink

    I did post another thread but nobody has replied to that and then I saw this thread where another user was describing the same problem. Here's my initial thread: http://forums.asp.net/t/1219593.aspx

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-18-2008, 8:30 AM
    • Loading...
    • happyfirst
    • Joined on 01-24-2008, 8:04 PM
    • Posts 54
    • Points 16

    ylDave:
    Good writeup happyfirst.  That is the same issue I'm seeing - the discrepancy between how master page file paths are getting resolved at runtime and at design time; probably a question / bug for Microsoft.  It is unclear whether it is the same issue for antsy pants since we don't have enough info on how his references are set up.  I'll post elsewhere and see if I can find an answer. 

    Thanks. I hope we find a resolution besides having to leave out the MasterPageFile setting from the aspx. I initially though antsy probem was same since he referenced linking the master page and moving the master page.

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-18-2008, 11:35 AM
    • Loading...
    • Beyondard
    • Joined on 01-18-2008, 3:47 PM
    • Posts 31
    • Points 59

    Strupi,

     thanks for that, I was looking on how to do that myself. however I still have trouble with linking external .js files in the head. how can I go about doing that?

    currently, I have a URL variable in the web.config and I'm using  

    src='<asp:Literal runat="server" text="<%$ AppSettings: URL %>"/>filename.js'
     
     to make the reference work even in sub folders. However, this can be troublesome in case someone cannot resolve the domain name of the server and is using the IP address or host name. is there a better way to do it?

     

  • Re: PROBLEM USING MASTER PAGE IN SUBFOLDERS

    02-18-2008, 12:59 PM
    • Loading...
    • Strupi
    • Joined on 02-10-2008, 2:59 AM
    • Sacramento, CA
    • Posts 8
    • Points 56

     Beyondard and all,

    Recommend Scott Mitchel's excellent article at   http://aspnet.4guysfromrolla.com/articles/052505-1.aspx 

    It appears that the Page.ResolveUrl() method he describes at the bottom of his article may be a one size fits all solution to all these problems.  I have not tried it yet.

    So the solution to your problem, Beyondard, may be  

    text = <%=Page.ResolveUrl("~/scripts/filename.js") %> 

    or something like it. 

    Jim Webber, Sacramento, California
Page 1 of 2 (21 items) 1 2 Next >