Link to home
Start Free TrialLog in
Avatar of chrisryhal
chrisryhal

asked on

Application Variable

I purchased some sourcecode off the net, and am getting errors referecing the below code:

        Dim strHomePageControl As String = Request.ApplicationPath & "templates/" & Application("Website_Template") & "/controls/home_page.ascx"

Where would I find Application("Website_Template")

In there readme, I am told its am application variable
Avatar of TornadoV
TornadoV
Flag of United States of America image

What happens if you replace & Application("Website_Template") with a name of an actual template that (I'm assuming) is included with the source code?

For example if your 'Templates' directory contains folders 'Template1', 'Template2', etc. see if you get an error running

Dim strHomePageControl As String = Request.ApplicationPath & "templates/" & "Template1" & "/controls/home_page.ascx"
Avatar of chrisryhal
chrisryhal

ASKER

Well, the error is actually doing something else.

My Isolated App name is called "DotNetDating" and as you can see in the path below, it referencing it a weird way.  The .CONFIG file stores the Variable like so:

\\\\\\\\\\\\\\\VARIABLE CODE\\\\\\\\\\\\\\

<appVar varName="Website_Template" value="blue_yellow_orange" fieldType="3" required="0" />

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\




\\\\\\\\\\\\\\ERROR MESSAGE\\\\\\\\\\\\\

The virtual path '/DotNetDatingtemplates/blue_yellow_orange/controls/home_page.ascx' maps to another application, which is not allowed.
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.Web.HttpException: The virtual path '/DotNetDatingtemplates/blue_yellow_orange/controls/home_page.ascx' maps to another application, which is not allowed.

Source Error:


Line 28:         'Dim strHomePageControl As String = "templates/" & Application("Website_Template") & "/controls/home_page.ascx"
Line 29:
Line 30:         Dim ucHomePage As System.Web.UI.UserControl = LoadControl(strHomePageControl)
Line 31:         ucHomePage.ID = "tplHome"
Line 32:         plHome.Controls.Add(ucHomePage)
 
"Where would I find Application("Website_Template")"  - take a look in Global.asax, perhaps it is set in there.

Is 'templates' a folder inside of your application?  How is it relative to the root of you project?  Is it a virtual folder?

Try to trick the asp.net engine by using an App-Based path with the '~' prefix instead of a classic virtual path, like this:

Dim strHomePageControl As String = "~/templates/" & Application("Website_Template") & "/controls/home_page.ascx"



Avatar of DBAduck - Ben Miller
The application variable is working as it is, because you can see below that "blue_yellow_orange" is being shown correctly.  But the error is in relation to the way the complete Virtual Path '/DotNetDatingtemplates/blue_yellow_orange/controls/home_page.ascx' is being referenced.  It looks like there is a virtual directory that is mapped somewhere else like pointing to another folder that is not in the current application, and that is not allowed.

Exception Details: System.Web.HttpException: The virtual path '/DotNetDatingtemplates/blue_yellow_orange/controls/home_page.ascx' maps to another application, which is not allowed.

So you would want to check out where the virtual directory '/DotNetDatingtemplates/blue_yellow_orange/controls/home_page.ascx' is pointing, or do a Server.MapPath to get the physical location of the .ascx file.  

Ben.
dbaduck:  Tried that with below result.  Everything is working great, other than the way this code is referencing the User Control.



\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ERROR\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Invalid path for MapPath 'M:\web\users\V004U37FEH\html\domain\tdp\templates\blue_yellow_orange\controls\header.ascx'. A virtual path is expected.
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.ArgumentException: Invalid path for MapPath 'M:\web\users\V004U37FEH\html\domain\tdp\templates\blue_yellow_orange\controls\header.ascx'. A virtual path is expected.

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.  

Stack Trace:


[ArgumentException: Invalid path for MapPath 'M:\web\users\V004U37FEH\html\domain\tdp\templates\blue_yellow_orange\controls\header.ascx'. A virtual path is expected.]
   System.Web.HttpRequest.MapPath(String virtualPath, String baseVirtualDir, Boolean allowCrossAppMapping) +429
   System.Web.HttpServerUtility.MapPath(String path) +60
   DotNetDating.header.Page_Load(Object sender, EventArgs e)
   System.Web.UI.Control.OnLoad(EventArgs e) +67
   System.Web.UI.Control.LoadRecursive() +35
   System.Web.UI.Control.LoadRecursive() +98
   System.Web.UI.Control.LoadRecursive() +98
   System.Web.UI.Page.ProcessRequestMain() +750







\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ VB CODE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Dim strHeaderPath As String = Server.MapPath("M:\web\users\V004U37FEH\domain\tdp\templates\blue_yellow_orange\controls\header.ascx")
        Dim ucHeader As System.Web.UI.UserControl = LoadControl(strHeaderPath)
        Me.Controls.Add(ucHeader)

        Me.Controls.Add(New System.Web.UI.LiteralControl("<title>" & Application("Website_Name") & "</title>" & vbNewLine))
        Me.Controls.Add(New System.Web.UI.LiteralControl("<META NAME=""keywords"" CONTENT=""" & Application("Website_Keywords") & """ />" & vbNewLine))

        Me.Controls.Add(New System.Web.UI.LiteralControl("<script language=javascript>"))
        Me.Controls.Add(New System.Web.UI.LiteralControl("function launchMessenger() {"))

        If DotNetDating_Core.functions.GetCookie("member_id") <> "ERROR" Then

            If Application("Website_Mode") <> "1" And DotNetDating_Core.functions.GetCookie("member_level_id") = "1" And DotNetDating_Core.functions.GetCookie("trial_expired") <> "0" Then

                Me.Controls.Add(New System.Web.UI.LiteralControl("document.location.href='" & Request.ApplicationPath & "members/upgrade.aspx';"))

            Else

                Me.Controls.Add(New System.Web.UI.LiteralControl("window.open('" & Request.ApplicationPath & "members/im/imbuddylist.aspx', 'Messenger', 'width=260,height=370,top=1,left=1,menus=no,toolbar=no=resizeable=no,status=no,scrollbars=no');"))

            End If

            Dim hsh As New System.Collections.Hashtable
            hsh.Add("@member_id", DotNetDating_Core.functions.GetCookie("member_id"))
            Dim sql_dr As System.Data.OleDb.OleDbDataReader = DotNetDating_Core.data_access.GetDataReader("members_header", hsh)

            Do While sql_dr.Read()

                Dim plNewMessagesCount As System.Web.UI.WebControls.PlaceHolder = ucHeader.FindControl("plNewMessagesCount")

                If Not plNewMessagesCount Is Nothing Then

                    plNewMessagesCount.Controls.Add(New System.Web.UI.LiteralControl(sql_dr("new_messages")))

                End If

            Loop

            sql_dr.Close()

            Dim plScreenName As System.Web.UI.WebControls.PlaceHolder = ucHeader.FindControl("plScreenName")

            If Not plScreenName Is Nothing Then

                plScreenName.Controls.Add(New System.Web.UI.LiteralControl(DotNetDating_Core.functions.GetCookie("login")))

            End If

        Else

            Me.Controls.Add(New System.Web.UI.LiteralControl("document.location.href='" & Request.ApplicationPath & "join/join.aspx';"))

        End If

        Me.Controls.Add(New System.Web.UI.LiteralControl("}"))
        Me.Controls.Add(New System.Web.UI.LiteralControl("</script>"))
        Me.Controls.Add(New System.Web.UI.LiteralControl("<script language=JavaScript src='" & Request.ApplicationPath & "javascripts/overlib.js'></script>"))

 
It has to be a virtual path on the server:

Dim strHeaderPath As String = Server.MapPath(""templates/" & Application("Website_Template") & "/controls/header.ascx")
Server.MapPath didn't work
Check out this article, it shows how to share user controls accross web applications:

http://aspalliance.com/335

This might help.
I appreciate it, but it don't help much being a VB programmer
ASKER CERTIFIED SOLUTION
Avatar of DBAduck - Ben Miller
DBAduck - Ben Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
dbaduck, you were right, no problem with the code.  Worked out fine after dumping into the root.