Server.MapPath in Global.asax

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sebastiano

    Server.MapPath in Global.asax

    I want to use Server.MapPath function in Global.asax because I want to save
    in an application variable the path of my database. Global.asax is in the
    root directory of my web folder and database is in database/database.mdb.
    Now, if I start my web site from default.aspx in the root folder all is ok,
    but if start it with a page in a nested folder Global.asax can't find the
    folder because Server.MapPath use the relative path of nested folder as base
    for its search.

    What can I do?

    Many thanks

    Sebastiano


  • Patrice

    #2
    Re: Server.MapPath in Global.asax

    Use an absolute path for the Server.MapPath argument such as
    ~/database/database.mdb instead of just database/database.mdb

    Patrice

    "Sebastiano " <info@sebastian ogazzola.it> a écrit dans le message de
    news:OtVprw4IEH A.3964@TK2MSFTN GP10.phx.gbl...[color=blue]
    > I want to use Server.MapPath function in Global.asax because I want to[/color]
    save[color=blue]
    > in an application variable the path of my database. Global.asax is in the
    > root directory of my web folder and database is in database/database.mdb.
    > Now, if I start my web site from default.aspx in the root folder all is[/color]
    ok,[color=blue]
    > but if start it with a page in a nested folder Global.asax can't find the
    > folder because Server.MapPath use the relative path of nested folder as[/color]
    base[color=blue]
    > for its search.
    >
    > What can I do?
    >
    > Many thanks
    >
    > Sebastiano
    >
    >[/color]


    Comment

    • Lostinet

      #3
      Re: Server.MapPath in Global.asax

      try to use Request.Physica lApplicationPat h to combine path

      --
      Thanks.

      Lostinet (MS ASP.NET MVP)
      lostinetweb@hot mail.com
      ---------------------------
      Need MessageBox,Comb oBox,DatePicker ,PasswordBox,Tr eeView,ASP.Net RPC ?

      "Sebastiano " <info@sebastian ogazzola.it> дÈëÏûÏ¢
      news:OtVprw4IEH A.3964@TK2MSFTN GP10.phx.gbl...[color=blue]
      > I want to use Server.MapPath function in Global.asax because I want to[/color]
      save[color=blue]
      > in an application variable the path of my database. Global.asax is in the
      > root directory of my web folder and database is in database/database.mdb.
      > Now, if I start my web site from default.aspx in the root folder all is[/color]
      ok,[color=blue]
      > but if start it with a page in a nested folder Global.asax can't find the
      > folder because Server.MapPath use the relative path of nested folder as[/color]
      base[color=blue]
      > for its search.
      >
      > What can I do?
      >
      > Many thanks
      >
      > Sebastiano
      >
      >[/color]


      Comment

      • Rashad Rivera

        #4
        Re: Server.MapPath in Global.asax

        Thank you so much, I can't understand why MS did not mention the importance
        of the "~" symbol in the path request. I have waisted hours trying to look
        for documentation.

        - Rashad

        "Patrice" <nobody@nowhere .com> wrote in message
        news:upo4Do6IEH A.3964@TK2MSFTN GP10.phx.gbl...[color=blue]
        > Use an absolute path for the Server.MapPath argument such as
        > ~/database/database.mdb instead of just database/database.mdb
        >
        > Patrice
        >
        > "Sebastiano " <info@sebastian ogazzola.it> a écrit dans le message de
        > news:OtVprw4IEH A.3964@TK2MSFTN GP10.phx.gbl...[color=green]
        > > I want to use Server.MapPath function in Global.asax because I want to[/color]
        > save[color=green]
        > > in an application variable the path of my database. Global.asax is in[/color][/color]
        the[color=blue][color=green]
        > > root directory of my web folder and database is in[/color][/color]
        database/database.mdb.[color=blue][color=green]
        > > Now, if I start my web site from default.aspx in the root folder all is[/color]
        > ok,[color=green]
        > > but if start it with a page in a nested folder Global.asax can't find[/color][/color]
        the[color=blue][color=green]
        > > folder because Server.MapPath use the relative path of nested folder as[/color]
        > base[color=green]
        > > for its search.
        > >
        > > What can I do?
        > >
        > > Many thanks
        > >
        > > Sebastiano
        > >
        > >[/color]
        >
        >[/color]


        Comment

        Working...