Simple Server.MapPath problem?

Discussion in 'ASP .Net' started by Oberon, May 11, 2005.

  1. Oberon

    Oberon Guest

    Why does this not work as it should?

    I expect index.aspx to show:.

    Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=c:\inetpub\wwwroot\ChatSimple\db\chatusers.mdb

    Instead, I get:

    Provider=Microsoft.Jet.OLEDB.4.0;Data
    Source=c:\inetpub\wwwroot\ChatSimple\chatusers.mdb\chatusers.mdb

    It is running on Windows XP Pro, SP1, IE6.


    1) IIS has been set with:

    ChatSimple, Properties, HTTP Headers, Enable Content Expiration
    (ticked), Content Should "Expire Immediately"

    Then restarted from the cmd line with:
    net stop W3SVC
    net start W3SVC


    2) Here is the Global.asax.vb

    + + + + + + +

    Imports System.Web
    Imports System.Web.SessionState

    Public Class Global
    Inherits System.Web.HttpApplication

    Public Sub New()
    MyBase.New()
    InitializeComponent()
    End Sub

    Private components As System.ComponentModel.IContainer
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()
    components = New System.ComponentModel.Container()
    End Sub

    Sub Application_Start(ByVal sender As Object, ByVal e As
    EventArgs)
    Application("ChatConnString") =
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    Server.MapPath("/db/ChatUsers.mdb")
    End Sub

    End Class

    + + + + + + +

    3) Here is the index.aspx page:

    + + + + + + +

    <%@ Page Language="vb" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <meta http-equiv=Content-Type content="text/html;
    charset=windows-1252">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="-1">
    <title>Chat Simple</title>
    </HEAD>
    <BODY>
    <%Response.Write(Application("ChatConnString"))
    Response.End %>
    </BODY></HTML>

    + + + + + + +
     
    Oberon, May 11, 2005
    #1
    1. Advertising

  2. Oberon

    Oberon Guest

    Application variable caching problem. What's going on?

    1) I had my browser cache off.

    Tools, Internet Options, General, Settings, Check for newer
    versions of stored pages - every visit to the page.

    2) I switched off IIS caching (see below)

    3) I set my HTTP headers (see below)

    4) Finally I added even more lines to index.aspx (see new
    version below).

    5) Restarted IIS, just for good measure.

    Nothing worked. Still the same obsolete application variable
    shown. Eventually I renamed the application variable to
    Application("dbConnString")) - effectively killing the old one.
    That worked, but before that, altering the value in the
    Application variable did nothing. eg.

    Application("ChatConnString") =
    "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    Server.MapPath("\")

    still gave the wrong value.

    Now (after renaming the Application variable) the Index.aspx
    page is showing nothing, which is an improvement on it showing
    the wrong value but ... why didn't the value change when I
    re-coded it in Global.aspx.vb.

    I'm totally baffled.

    + + + + + + +
    New Index.aspx with more code to kill cached pages.
    + + + + + + +
    <%@ Page Language="vb" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <meta http-equiv=Content-Type content="text/html;
    charset=windows-1252">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="-1">
    <title>Chat Simple</title>
    </HEAD>
    <BODY>
    <% Response.CacheControl = "no-cache" %>
    <% Response.Expires = -1 %>

    <%Response.Write(Application("dbConnString"))
    Response.End %>
    </BODY></HTML>
    + + + + + + +

    The only thing that actually worked

    On Wed, 11 May 2005 11:40:01 GMT, Oberon <>
    wrote:

    >Why does this not work as it should?
    >
    >I expect index.aspx to show:.
    >
    >Provider=Microsoft.Jet.OLEDB.4.0;Data
    >Source=c:\inetpub\wwwroot\ChatSimple\db\chatusers.mdb
    >
    >Instead, I get:
    >
    >Provider=Microsoft.Jet.OLEDB.4.0;Data
    >Source=c:\inetpub\wwwroot\ChatSimple\chatusers.mdb\chatusers.mdb
    >
    >It is running on Windows XP Pro, SP1, IE6.
    >
    >
    >1) IIS has been set with:
    >
    >ChatSimple, Properties, HTTP Headers, Enable Content Expiration
    >(ticked), Content Should "Expire Immediately"
    >
    >Then restarted from the cmd line with:
    >net stop W3SVC
    >net start W3SVC
    >
    >
    >2) Here is the Global.asax.vb
    >
    > + + + + + + +
    >
    >Imports System.Web
    >Imports System.Web.SessionState
    >
    >Public Class Global
    > Inherits System.Web.HttpApplication
    >
    > Public Sub New()
    > MyBase.New()
    > InitializeComponent()
    > End Sub
    >
    > Private components As System.ComponentModel.IContainer
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub
    >InitializeComponent()
    > components = New System.ComponentModel.Container()
    > End Sub
    >
    > Sub Application_Start(ByVal sender As Object, ByVal e As
    >EventArgs)
    > Application("ChatConnString") =
    >"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    >Server.MapPath("/db/ChatUsers.mdb")
    > End Sub
    >
    >End Class
    >
    > + + + + + + +
    >
    >3) Here is the index.aspx page:
    >
    > + + + + + + +
    >
    ><%@ Page Language="vb" %>
    ><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    ><HTML>
    ><HEAD>
    > <meta http-equiv=Content-Type content="text/html;
    >charset=windows-1252">
    > <meta http-equiv="Pragma" content="no-cache">
    > <meta http-equiv="Expires" content="-1">
    > <title>Chat Simple</title>
    ></HEAD>
    ><BODY>
    ><%Response.Write(Application("ChatConnString"))
    > Response.End %>
    ></BODY></HTML>
    >
    > + + + + + + +
     
    Oberon, May 11, 2005
    #2
    1. Advertising

  3. That code works fine here. Did you do an iisreset after a previous test?

    BTW, you might find it easier and more secure to put that string in the
    web.config.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetsec/html/SecNetHT08.asp

    Ken

    "Oberon" <> wrote in message
    news:...
    > Why does this not work as it should?
    >
    > I expect index.aspx to show:.
    >
    > Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=c:\inetpub\wwwroot\ChatSimple\db\chatusers.mdb
    >
    > Instead, I get:
    >
    > Provider=Microsoft.Jet.OLEDB.4.0;Data
    > Source=c:\inetpub\wwwroot\ChatSimple\chatusers.mdb\chatusers.mdb
    >
    > It is running on Windows XP Pro, SP1, IE6.
    >
    >
    > 1) IIS has been set with:
    >
    > ChatSimple, Properties, HTTP Headers, Enable Content Expiration
    > (ticked), Content Should "Expire Immediately"
    >
    > Then restarted from the cmd line with:
    > net stop W3SVC
    > net start W3SVC
    >
    >
    > 2) Here is the Global.asax.vb
    >
    > + + + + + + +
    >
    > Imports System.Web
    > Imports System.Web.SessionState
    >
    > Public Class Global
    > Inherits System.Web.HttpApplication
    >
    > Public Sub New()
    > MyBase.New()
    > InitializeComponent()
    > End Sub
    >
    > Private components As System.ComponentModel.IContainer
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub
    > InitializeComponent()
    > components = New System.ComponentModel.Container()
    > End Sub
    >
    > Sub Application_Start(ByVal sender As Object, ByVal e As
    > EventArgs)
    > Application("ChatConnString") =
    > "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
    > Server.MapPath("/db/ChatUsers.mdb")
    > End Sub
    >
    > End Class
    >
    > + + + + + + +
    >
    > 3) Here is the index.aspx page:
    >
    > + + + + + + +
    >
    > <%@ Page Language="vb" %>
    > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    > <HTML>
    > <HEAD>
    > <meta http-equiv=Content-Type content="text/html;
    > charset=windows-1252">
    > <meta http-equiv="Pragma" content="no-cache">
    > <meta http-equiv="Expires" content="-1">
    > <title>Chat Simple</title>
    > </HEAD>
    > <BODY>
    > <%Response.Write(Application("ChatConnString"))
    > Response.End %>
    > </BODY></HTML>
    >
    > + + + + + + +
    >
     
    Ken Cox [Microsoft MVP], May 11, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon
    Replies:
    5
    Views:
    11,368
    Scott M.
    Jan 17, 2010
  2. Peter Row
    Replies:
    0
    Views:
    490
    Peter Row
    Mar 1, 2004
  3. =?Utf-8?B?dHBhcmtzNjk=?=

    server.mappath vs. request.mappath

    =?Utf-8?B?dHBhcmtzNjk=?=, Mar 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,228
    Juan T. Llibre
    Mar 11, 2007
  4. Replies:
    4
    Views:
    1,009
    Juan T. Llibre
    Oct 7, 2007
  5. AAaron123
    Replies:
    11
    Views:
    1,222
    AAaron123
    Sep 9, 2009
Loading...

Share This Page