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_Templ ate") & "/controls/home_page.ascx"
Where would I find Application("Website_Templ ate")
In there readme, I am told its am application variable
Dim strHomePageControl As String = Request.ApplicationPath & "templates/" & Application("Website_Templ
Where would I find Application("Website_Templ
In there readme, I am told its am application variable
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/bl ue_yellow_ orange/con trols/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/bl ue_yellow_ orange/con trols/home _page.ascx ' maps to another application, which is not allowed.
Source Error:
Line 28: 'Dim strHomePageControl As String = "templates/" & Application("Website_Templ ate") & "/controls/home_page.ascx"
Line 29:
Line 30: Dim ucHomePage As System.Web.UI.UserControl = LoadControl(strHomePageCon trol)
Line 31: ucHomePage.ID = "tplHome"
Line 32: plHome.Controls.Add(ucHome Page)
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"
\\\\\\\\\\\\\\\\\\\\\\\\\\
\\\\\\\\\\\\\\ERROR MESSAGE\\\\\\\\\\\\\
The virtual path '/DotNetDatingtemplates/bl
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/bl
Source Error:
Line 28: 'Dim strHomePageControl As String = "templates/" & Application("Website_Templ
Line 29:
Line 30: Dim ucHomePage As System.Web.UI.UserControl = LoadControl(strHomePageCon
Line 31: ucHomePage.ID = "tplHome"
Line 32: plHome.Controls.Add(ucHome
"Where would I find Application("Website_Templ ate")" - 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_Templ ate") & "/controls/home_page.ascx"
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_Templ
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/bl ue_yellow_ orange/con trols/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/bl ue_yellow_ orange/con trols/home _page.ascx ' maps to another application, which is not allowed.
So you would want to check out where the virtual directory '/DotNetDatingtemplates/bl ue_yellow_ orange/con trols/home _page.ascx ' is pointing, or do a Server.MapPath to get the physical location of the .ascx file.
Ben.
Exception Details: System.Web.HttpException: The virtual path '/DotNetDatingtemplates/bl
So you would want to check out where the virtual directory '/DotNetDatingtemplates/bl
Ben.
ASKER
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\h tml\domain \tdp\templ ates\blue_ yellow_ora nge\contro ls\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\h tml\domain \tdp\templ ates\blue_ yellow_ora nge\contro ls\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\h tml\domain \tdp\templ ates\blue_ yellow_ora nge\contro ls\header. ascx'. A virtual path is expected.]
System.Web.HttpRequest.Map Path(Strin g virtualPath, String baseVirtualDir, Boolean allowCrossAppMapping) +429
System.Web.HttpServerUtili ty.MapPath (String path) +60
DotNetDating.header.Page_L oad(Object sender, EventArgs e)
System.Web.UI.Control.OnLo ad(EventAr gs e) +67
System.Web.UI.Control.Load Recursive( ) +35
System.Web.UI.Control.Load Recursive( ) +98
System.Web.UI.Control.Load Recursive( ) +98
System.Web.UI.Page.Process RequestMai n() +750
\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\ VB CODE \\\\\\\\\\\\\\\\\\\\\\\\\\ \\\\\\\\\\ \\
Dim strHeaderPath As String = Server.MapPath("M:\web\use rs\V004U37 FEH\domain \tdp\templ ates\blue_ yellow_ora nge\contro ls\header. ascx")
Dim ucHeader As System.Web.UI.UserControl = LoadControl(strHeaderPath)
Me.Controls.Add(ucHeader)
Me.Controls.Add(New System.Web.UI.LiteralContr ol("<title >" & Application("Website_Name" ) & "</title>" & vbNewLine))
Me.Controls.Add(New System.Web.UI.LiteralContr ol("<META NAME=""keywords"" CONTENT=""" & Application("Website_Keywo rds") & """ />" & vbNewLine))
Me.Controls.Add(New System.Web.UI.LiteralContr ol("<scrip t language=javascript>"))
Me.Controls.Add(New System.Web.UI.LiteralContr ol("functi on launchMessenger() {"))
If DotNetDating_Core.function s.GetCooki e("member_ id") <> "ERROR" Then
If Application("Website_Mode" ) <> "1" And DotNetDating_Core.function s.GetCooki e("member_ level_id") = "1" And DotNetDating_Core.function s.GetCooki e("trial_e xpired") <> "0" Then
Me.Controls.Add(New System.Web.UI.LiteralContr ol("docume nt.locatio n.href='" & Request.ApplicationPath & "members/upgrade.aspx';"))
Else
Me.Controls.Add(New System.Web.UI.LiteralContr ol("window .open('" & Request.ApplicationPath & "members/im/imbuddylist.as px', 'Messenger', 'width=260,height=370,top= 1,left=1,m enus=no,to olbar=no=r esizeable= no,status= no,scrollb ars=no');" ))
End If
Dim hsh As New System.Collections.Hashtab le
hsh.Add("@member_id", DotNetDating_Core.function s.GetCooki e("member_ id"))
Dim sql_dr As System.Data.OleDb.OleDbDat aReader = DotNetDating_Core.data_acc ess.GetDat aReader("m embers_hea der", hsh)
Do While sql_dr.Read()
Dim plNewMessagesCount As System.Web.UI.WebControls. PlaceHolde r = ucHeader.FindControl("plNe wMessagesC ount")
If Not plNewMessagesCount Is Nothing Then
plNewMessagesCount.Control s.Add(New System.Web.UI.LiteralContr ol(sql_dr( "new_messa ges")))
End If
Loop
sql_dr.Close()
Dim plScreenName As System.Web.UI.WebControls. PlaceHolde r = ucHeader.FindControl("plSc reenName")
If Not plScreenName Is Nothing Then
plScreenName.Controls.Add( New System.Web.UI.LiteralContr ol(DotNetD ating_Core .functions .GetCookie ("login")) )
End If
Else
Me.Controls.Add(New System.Web.UI.LiteralContr ol("docume nt.locatio n.href='" & Request.ApplicationPath & "join/join.aspx';"))
End If
Me.Controls.Add(New System.Web.UI.LiteralContr ol("}"))
Me.Controls.Add(New System.Web.UI.LiteralContr ol("</scri pt>"))
Me.Controls.Add(New System.Web.UI.LiteralContr ol("<scrip t language=JavaScript src='" & Request.ApplicationPath & "javascripts/overlib.js'>< /script>") )
\\\\\\\\\\\\\\\\\\\\\\\\\\
Invalid path for MapPath 'M:\web\users\V004U37FEH\h
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\h
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\h
System.Web.HttpRequest.Map
System.Web.HttpServerUtili
DotNetDating.header.Page_L
System.Web.UI.Control.OnLo
System.Web.UI.Control.Load
System.Web.UI.Control.Load
System.Web.UI.Control.Load
System.Web.UI.Page.Process
\\\\\\\\\\\\\\\\\\\\\\\\\\
Dim strHeaderPath As String = Server.MapPath("M:\web\use
Dim ucHeader As System.Web.UI.UserControl = LoadControl(strHeaderPath)
Me.Controls.Add(ucHeader)
Me.Controls.Add(New System.Web.UI.LiteralContr
Me.Controls.Add(New System.Web.UI.LiteralContr
Me.Controls.Add(New System.Web.UI.LiteralContr
Me.Controls.Add(New System.Web.UI.LiteralContr
If DotNetDating_Core.function
If Application("Website_Mode"
Me.Controls.Add(New System.Web.UI.LiteralContr
Else
Me.Controls.Add(New System.Web.UI.LiteralContr
End If
Dim hsh As New System.Collections.Hashtab
hsh.Add("@member_id", DotNetDating_Core.function
Dim sql_dr As System.Data.OleDb.OleDbDat
Do While sql_dr.Read()
Dim plNewMessagesCount As System.Web.UI.WebControls.
If Not plNewMessagesCount Is Nothing Then
plNewMessagesCount.Control
End If
Loop
sql_dr.Close()
Dim plScreenName As System.Web.UI.WebControls.
If Not plScreenName Is Nothing Then
plScreenName.Controls.Add(
End If
Else
Me.Controls.Add(New System.Web.UI.LiteralContr
End If
Me.Controls.Add(New System.Web.UI.LiteralContr
Me.Controls.Add(New System.Web.UI.LiteralContr
Me.Controls.Add(New System.Web.UI.LiteralContr
It has to be a virtual path on the server:
Dim strHeaderPath As String = Server.MapPath(""templates /" & Application("Website_Templ ate") & "/controls/header.ascx")
Dim strHeaderPath As String = Server.MapPath(""templates
ASKER
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.
http://aspalliance.com/335
This might help.
ASKER
I appreciate it, but it don't help much being a VB programmer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
dbaduck, you were right, no problem with the code. Worked out fine after dumping into the root.
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"