Server.MapPath in Global.asax

Discussion in 'ASP .Net' started by Sebastiano, Apr 16, 2004.

  1. Sebastiano

    Sebastiano Guest

    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
    Sebastiano, Apr 16, 2004
    #1
    1. Advertising

  2. Sebastiano

    Patrice Guest

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

    Patrice

    "Sebastiano" <> a écrit dans le message de
    news:...
    > 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, Apr 16, 2004
    #2
    1. Advertising

  3. Sebastiano

    Lostinet Guest

    try to use Request.PhysicalApplicationPath to combine path

    --
    Thanks.

    Lostinet (MS ASP.NET MVP)

    ---------------------------
    Need MessageBox,ComboBox,DatePicker,PasswordBox,TreeView,ASP.Net RPC ?
    http://www.lostinet.com/
    "Sebastiano" <> дÈëÏûÏ¢
    news:...
    > 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
    >
    >
    Lostinet, Apr 16, 2004
    #3
  4. 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" <> wrote in message
    news:...
    > Use an absolute path for the Server.MapPath argument such as
    > ~/database/database.mdb instead of just database/database.mdb
    >
    > Patrice
    >
    > "Sebastiano" <> a écrit dans le message de
    > news:...
    > > 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
    > >
    > >

    >
    >
    Rashad Rivera, Apr 16, 2004
    #4
    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. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    796
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  2. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,136
    Mark Rae
    May 23, 2006
  3. teo
    Replies:
    7
    Views:
    979
  4. Michael
    Replies:
    0
    Views:
    481
    Michael
    Feb 3, 2007
  5. =?Utf-8?B?dHBhcmtzNjk=?=

    server.mappath vs. request.mappath

    =?Utf-8?B?dHBhcmtzNjk=?=, Mar 10, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    1,128
    Juan T. Llibre
    Mar 11, 2007
Loading...

Share This Page