Using a Custom MasterPage


InstantForum Question
Hi

Does anyone know how i can run my masterpage as a masterpage for the forum master page?

i have this line in the forum masterpage:

<%@ Master Language="cs" Inherits="InstantASP.InstantForum.UI.Controls.Master" MasterPageFile="~/../entertainment.master" EnableViewState="false" %>

but then i get this errror:

Parser Error Message: The virtual path '/entertainment.master' maps to another application, which is not allowed.

obviously it's in the root directory, not the forum iis appliication directory.

anyone have any ideas for fixes?

thanks in advance



Entertainment.fm, Nightclubs, Restaurants, Hotels, Bars, Forums, Chat Rooms, Polls - Your playground on the internet!!
InstantForum Question

Hi Mac,

I hope your well. That's a great question. 

It's certainly possible to swap out the standard InstantForum MasterPage.master with your own custom master page however you should be aware that the InstantForum MasterPage contains a  number of controls that will be lost unless you copy these into your master page and set-up via the Page_Load event for your MasterPage.

For example we have checks within our MasterPage Page_Load event to check if the current user is authenticated and display the appropriate options (login or profile).We also set-up some navigation options such as the Explore menu via the MasterPage code-behind so we can apply role based security to the forum list shown within the Explore menu.

You will lose some of this functionality if you completely swap out the InstantForum master page. If you wanted to add controls that appear within the InstantForum MasterPage back into your custom MasterPage you would need to copy these controls from the InstantForum MasterPage.Master into your MasterPage as well as the associated code-behind that sets up the control from the InstantASP.InstantForum.UI/MasterPage.cs file. 

The easiest way to use your master page is to simply pop a copy of your "entertainment.master" into the root of the skin folder used for your forum. 

You'll need to rename "entertainment.master" to "MasterPage.Master". I'd suggest renaming the existing MasterPage.Master to something like OldMasterPage.Master.  This will save you having to go through each .aspx within InstantForum and updating the MasterPage property from "MasterPage.Mater" to "entertainment.master".

If your entertainment.master has any dependencies on compiled DLLs you'll need to ensure these DLLs are copied into the bin folder for the child forum application. 

Also if you have a entertainment.master.cs or entertainment.master.vb you'll need to ensure this code-behind is also copied alongside your mater page. 

If you prefer not to duplicate your entertainment.master another option may be to add a virtual directory into your forum application within IIS called "shared". This virtual directory would point to the root of your parent application. You could then use...

MasterPageFile="~/shared/entertainment.master"

As your root web site contains a web.config and bin folder you may need to ensure the virtual directory is also marked as a web application within IIS. Once created you can right click the virtual directory and select "Convert to Application" within IIS. 

If your looking to simply wrap static HTML around InstantForum and your entertainment.master contains this HTML (with no dynamic server side code you need to preserve) the easiest option may be to simply copy the existing static HTML for your master page into the standard MasterPage.Master file and reference any CSS / JS you need from the MasterPage.Master file. This way you don't need to worry about dependencies or adding virtual directories within IIS etc. 

Does this help Mac. I've not had a chance to test these ideas however if they fail please let me know and I'll certainly investigate in more detail. 

I look forward to hearing from you and assisting further, 

http://www.instantasp.co.uk/images/line.gif
Kindest Regards,

Ryan Healey



ryan@instantasp.co.uk
www.instantasp.co.uk
Blog | Community | Docs

http://www.instantasp.co.uk/core/assets/images/email/facebook.png http://www.instantasp.co.uk/core/assets/images/email/twitter.png http://www.instantasp.co.uk/core/assets/images/email/google.png http://www.instantasp.co.uk/core/assets/images/email/linkedin.png

Thanks Ryan

I'm using the shared directory as an IIS application option.I get this error

Parser Error

Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load file or assembly 'Telerik.Web.UI' or one of its dependencies. The system cannot find the file specified.
Source Error:
[No relevant source lines]

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34212

Which is solved by copying the relevant dll's (there were a few) from the root bin directory to the forum bin directory.

is there a way too reference the dll's from the root bin directory (as these will change over time) (not too much of a biggie though).

After having done that i now get this error, and am a bit stumped:

Server Error in '/Forum' Application.

Content controls have to be top-level controls in a content page or a nested master page that references a master page.

I'll keep looking for a solution, and will tell you if i find anything before the cavalry arrives.

Thanks

Mac

Entertainment.fm, Nightclubs, Restaurants, Hotels, Bars, Forums, Chat Rooms, Polls - Your playground on the internet!!

Hi Mac,

Your right. The first issues is due to web.config inheritance. As you've added the Shared virtual directory pointing to your main site under the forum the <handlers> and <modules> registered within the InstantForum web.cnfig will inherit into your "Shared" virtual directory / application. 

As you suggest you can copy the DLLs referenced in the forum web.config into your web site root bin folder. This will mean you have 2 copies of the DLLS

To avoid this you could also add a <clear/> element within the <handlers> and <modules> elements within your web.config. This should prevent the forum handlers and modules from being inherited when you use the "Shared" virtual directory to access your custom master page.

If your using a Classic .NET application pool (which I doubt you are) you'll also need to ensure you clear the <httpModules> and <httpHandlers> elements within the <system.web> section of your web.config. 

With regards to error you are seeing - "Content controls have to be top-level controls in a content page or a nested master page that references a master page".

Taking a closer look at your code Mac I'm not sure you can actually set the MasterPageFile property within the MasterPage it's self. Typically this is set from the content pages that are loaded into the content place holder for the master page you have specific for the page. 

To test this with the forum homepage Mac try the steps below...

1. Open Default.aspx.cs in NotePad

Add a Page_PreInit event as below to load your MasterPage around Default.aspx....

using System;

namespace InstantASP.InstantForum.Pages
{

partial class Default : Pages.Base.UserPage
{

   protected override void Page_PreInit(object sender, System.EventArgs e)
   {

    this.MasterPageFile = "~/Shared/entertainment.master";
    base.Page_PreInit(sender, e);

   }

}

}


Once you make this change you should see our Default.aspx page load inside the content placeholder on your entertainment master page. 

If this works please let me know and I'll assist to provide a quick way to add this to all pages. I look forward to your response and assisting further, 


http://www.instantasp.co.uk/images/line.gif
Kindest Regards,

Ryan Healey



ryan@instantasp.co.uk
www.instantasp.co.uk
Blog | Community | Docs

http://www.instantasp.co.uk/core/assets/images/email/facebook.png http://www.instantasp.co.uk/core/assets/images/email/twitter.png http://www.instantasp.co.uk/core/assets/images/email/google.png http://www.instantasp.co.uk/core/assets/images/email/linkedin.png

i have this in my masterpage:

<asp:ContentPlaceHolder ID="mainbody" runat="server">
  </asp:ContentPlaceHolder>


there fore all the content for the forums needs to be in this (excluding the header stuff):

<asp:Content ID="Content1" ContentPlaceHolderID="mainbody" runat="server">
forum contents
</asp:Content>


i now get this error:

Server Error in '/Forum' Application.

Only one instance of a ScriptManager can be added to the page.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Only one instance of a ScriptManager can be added to the page.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

More to follow soon. Thanks.

Entertainment.fm, Nightclubs, Restaurants, Hotels, Bars, Forums, Chat Rooms, Polls - Your playground on the internet!!

I've just seen your post and believe this will help my current issue, let me try that and get back to you, thanks ryan!




Entertainment.fm, Nightclubs, Restaurants, Hotels, Bars, Forums, Chat Rooms, Polls - Your playground on the internet!!

almost there...

solved the last problem, but now have this:

not sure which bin folder it is referencing?

Server Error in '/Forum' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0234: The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
Source Error:
Line 1: using System;Line 2: using System.Web;Line 3: using System.Data.SqlClient;Line 4: using InstantASP.Common.Configuration;Line 5: using InstantASP.Common.Providers;

Source File: c:\inetpub\wwwroot\Forum\Global.asax.cs  Line: 3
Show Detailed Compiler Output:
c:\windows\system32\inetsrv> "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe" /t:library /utf8output /R:"C:\Windows\Microsoft.Net\assembly\GAC_64\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll" /R:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\forum\286f4b06\2e6e7139\App_Code.hwepqrj-.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Design\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Design.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing.Design\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.Design.dll" /R:"C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Web.Extensions.Design\v4.0_4.0.0.0__31bf3856ad364e35\System.Web.Extensions.Design.dll" /out:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\forum\286f4b06\2e6e7139\App_global.asax.ws0fqwrz.dll" /D:DEBUG /debug+ /optimize- /w:4 /nowarn:1659;1699;1701;612;618 /warnaserror- "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\forum\286f4b06\2e6e7139\App_global.asax.ws0fqwrz.0.cs" "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\forum\286f4b06\2e6e7139\App_global.asax.ws0fqwrz.1.cs" "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\forum\286f4b06\2e6e7139\App_global.asax.ws0fqwrz.2.cs"Microsoft (R) Visual C# Compiler version 4.0.30319.33440for Microsoft (R) .NET Framework 4.5Copyright (C) Microsoft Corporation. All rights reserved.c:\inetpub\wwwroot\Forum\Global.asax.cs(3,19): error CS0234: The type or namespace name 'SqlClient' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)c:\inetpub\wwwroot\Forum\Global.asax.cs(4,18): error CS0234: The type or namespace name 'Common' does not exist in the namespace 'InstantASP' (are you missing an assembly reference?)c:\inetpub\wwwroot\Forum\Global.asax.cs(5,18): error CS0234: The type or namespace name 'Common' does not exist in the namespace 'InstantASP' (are you missing an assembly reference?)c:\inetpub\wwwroot\Forum\Global.asax.cs(6,18): error CS0234: The type or namespace name 'Common' does not exist in the namespace 'InstantASP' (are you missing an assembly reference?)c:\inetpub\wwwroot\Web.config(186,18): error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?)c:\inetpub\wwwroot\Web.config(185,18): error CS0234: The type or namespace name 'Linq' does not exist in the namespace 'System' (are you missing an assembly reference?)

i believe that nesting masterpages is no problem:
https://msdn.microsoft.com/en-us/library/vstudio/bb547109%28v=vs.100%29.aspx

I've gotta go, and i know it's the end of your day, but if you have any brain waves, please feel free to comment

have a great evening, thanks for the help!

Entertainment.fm, Nightclubs, Restaurants, Hotels, Bars, Forums, Chat Rooms, Polls - Your playground on the internet!!

Don't worry my project seems to have just dropped all of it's references!!

my problem not yours

and what a problem




Entertainment.fm, Nightclubs, Restaurants, Hotels, Bars, Forums, Chat Rooms, Polls - Your playground on the internet!!

Hi Mac,

Just wanted to thank you for sharing. I'm sorry i never responded sooner. 

If you run into any further problems please don't hesitate to respond and I'll certainly assist. 

http://www.instantasp.co.uk/images/line.gif
Kindest Regards,

Ryan Healey



ryan@instantasp.co.uk
www.instantasp.co.uk
Blog | Community | Docs

http://www.instantasp.co.uk/core/assets/images/email/facebook.png http://www.instantasp.co.uk/core/assets/images/email/twitter.png http://www.instantasp.co.uk/core/assets/images/email/google.png http://www.instantasp.co.uk/core/assets/images/email/linkedin.png
GO

Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....







InstantASP Forums


Search