Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 8 of 8

Thread: Including template.ascx in external pages

  1. #1
    sprogg is offline Member
    Join Date
    Jan 2009
    Posts
    79

    Default Including template.ascx in external pages

    We have a website where aspdotnetstorefront is only a part of the overall site, however as we started the development initially with aspdnsf we want to use the features from the template.ascx page (display cart/login etc) throught the rest of the site.

    Is this possible and if so how is it achieved?

  2. #2
    weblingo is offline Member
    Join Date
    Feb 2008
    Location
    Bristol, UK
    Posts
    63

    Default

    We also have this requirement - does anyone have any ideas if this is possible?

    We currently maintain site nav / page headers & footers etc twice, once in the main site and once in ASPDNSF. Would be fantastic to fully integrate this and also to have signin links / cart tokens etc more widely available

  3. #3
    ASPDNSF Staff - Jon's Avatar
    ASPDNSF Staff - Jon is offline Senior Member
    Join Date
    Sep 2004
    Posts
    11,419

    Default

    Are the two sites running within the same AppDomain? The difficulty is that asp.net probably sees the sites as separate sites, and won't allow one site to party on the resources of another one.

    If there was a way to combine the sites, and use one common web.config, you could simply inherit each page from SkinBase to achieve the same look and feel.
    Jon Wolthuis

  4. #4
    weblingo is offline Member
    Join Date
    Feb 2008
    Location
    Bristol, UK
    Posts
    63

    Default

    Truly excellent post Jon - thanks for that

    They are running under the same site with one web.config. I have added SkinBase to inheritance and that works fine for all pages in the root of the site (fantastic!), but all pages in sub folders are using a relative path to look for the template, and the skins folder is obviously back at root

    I have tried making the path absolute in SkinBase.cs, but end up with "The virtual path '/skins/skin_1/template.ascx' maps to another application, which is not allowed"

    I would be very grateful if we could get this working

    Thanks

  5. #5
    ASPDNSF Staff - Jon's Avatar
    ASPDNSF Staff - Jon is offline Senior Member
    Join Date
    Sep 2004
    Posts
    11,419

    Default

    The error, "The virtual path '< path >' maps to another application, which is not allowed", is generated by IIS when two Applications point to the same physical folder.

    For server-side controls, the "tilde" can be added to resolve paths from the correct Application root: "~/skins/skin_1/< etc >". However, for html elements that aren't marked "runat=server", the tilde isn't resolved, but instead passed directly to the browser, which is obviously not correct.

    One method is to wrap all relative Urls inside a new function, "ResolveUrl()", like this: ResolveUrl("~/skins/skin_1/< etc >")

    The ResolveUrl function that I use looks like this:
    Code:
            /// <summary>
            /// Returns a site relative HTTP path from a partial path starting out with a ~.
            /// Same syntax that ASP.Net internally supports but this method can be used
            /// outside of the Page framework.
            /// 
            /// Works like Control.ResolveUrl including support for ~ syntax
            /// but returns an absolute URL.
            /// </summary>
            /// <param name="originalUrl">Any Url including those starting with ~</param>
            /// <returns>relative url</returns>
            public static string ResolveUrl(string originalUrl)
            {
                if (originalUrl == null) return null;
    
                // *** Absolute path - just return
                if (originalUrl.IndexOf("://") != -1) return originalUrl;
    
                // *** Fix up image path for ~ root app dir directory
                if (originalUrl.StartsWith("~"))
                {
                    string newUrl = "";
                    if (HttpContext.Current != null) newUrl = HttpContext.Current.Request.ApplicationPath + originalUrl.Substring(1).Replace("//", "/");
                    else throw new ArgumentException("Invalid URL: Relative URL not allowed."); // *** Not context: assume current directory is the base directory
    
                    // *** Just to be sure fix up any double slashes
                    return newUrl;
                }
    
                return originalUrl;
            }
    Hope this helps.
    Jon Wolthuis

  6. #6
    weblingo is offline Member
    Join Date
    Feb 2008
    Location
    Bristol, UK
    Posts
    63

    Default

    Thanks again Jon

    I have changed SkinBase.cs to check for the template using "~/" + SkinRoot if the prior checks fail. That now works fine.

    Then I had to change EntityHelper.cs to prefix the path in XslFilePath with "~/". All good.

    But now the CSS files actually in the template.ascx file are not being linked correctly when the page is in a subfolder. Any suggestions on how to sort those too, please? I'm hoping that will be the last thing to sort!

    I really appreciate your help - thanks

  7. #7
    weblingo is offline Member
    Join Date
    Feb 2008
    Location
    Bristol, UK
    Posts
    63

    Default

    Turns out that href="/skins/Skin_(!SKINID!)/stylesheet.css" works fine on the server (the live site), where the root of the site truly is root, but it doesn't work on my local dev machine...

    Does anyone know of any VS project/solution settings which would make this come right?

    Thanks

  8. #8
    virtualtap is offline Senior Member
    Join Date
    May 2007
    Posts
    171

    Default

    For local Machine issue I am not sure what to do but here is how I am handling this original issue,

    I am not 100% on this as I am still building out the app, but so far it seems to be working

    in SkinBase.cs


    C#/VB.NET Code:
    get
    {
    return 
    String.Format("skins/skin_{0}/"this.SkinID);


    Replace with

    C#/VB.NET Code:
    get
    {
    if (!
    AppLogic.IsAdminSite)
                    {
                        return 
    String.Format("skins/skin_{0}/"this.SkinID);
                    }
                    else
                    {
                       return 
    String.Format("/skins/skin_{0}/"this.SkinID);
                    }


    then do the same for the .............return String.Format("skins/skin_{0}/images/
    Last edited by virtualtap; 02-25-2010 at 11:28 PM.
    MSX