?
Solved

Application Variable

Posted on 2006-05-08
11
Medium Priority
?
437 Views
Last Modified: 2007-12-19
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
0
Comment
Question by:chrisryhal
  • 5
  • 4
  • 2
11 Comments
 
LVL 11

Expert Comment

by:TornadoV
ID: 16631212
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"
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 16632114
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)
 
0
 
LVL 11

Expert Comment

by:TornadoV
ID: 16632411
"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"



0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 25

Expert Comment

by:DBAduck - Ben Miller
ID: 16633322
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.
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 16641340
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>"))

 
0
 
LVL 11

Expert Comment

by:TornadoV
ID: 16641393
It has to be a virtual path on the server:

Dim strHeaderPath As String = Server.MapPath(""templates/" & Application("Website_Template") & "/controls/header.ascx")
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 16642023
Server.MapPath didn't work
0
 
LVL 11

Expert Comment

by:TornadoV
ID: 16642195
Check out this article, it shows how to share user controls accross web applications:

http://aspalliance.com/335

This might help.
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 16642326
I appreciate it, but it don't help much being a VB programmer
0
 
LVL 25

Accepted Solution

by:
DBAduck - Ben Miller earned 2000 total points
ID: 16644157
I do not think that there was anything actually wrong with the original code after looking at it a little more in the error message.

What this means is that the directory Virtual Path '/DotNetDatingtemplates/blue_yellow_orange/controls/' has an application in it.

That means that either /DotNetDatingTemplates, or blue_yellow_orange, or controls has an application defined in IIS for whichever directory.  If you remove the application from it then it will load the .ascx without error.

You need to make sure that you do not need that folder to be an application, but I suspect this is an oversight, but you will want to check.

Ben.
0
 
LVL 2

Author Comment

by:chrisryhal
ID: 16851264
dbaduck, you were right, no problem with the code.  Worked out fine after dumping into the root.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question