tags:

views:

112

answers:

1

Heres my code:

XElement navegacion;
    public Navegacion()
    {
        this.navegacion = XElement.Load(HttpContext.Current.Server.MapPath("App_Data/navegacion.xml"));
    }

It works just fine when I go to:

http://localhost/Default.aspx

an when I go to

http://localhost/Users

But it cant open the file when I go to

http://localhost/Users/Index

or

http://localhost/Users/Index/1

or any other id for that matter.

Navegacion class is a Model.

Is there a way to fix this?

+1  A: 

You need to add another slash before the path to make it relative to the root, and not the current folder. That is why it works on Default.aspx, but not /Home etc, as that makes MapPath return /Home/App_Data/navegacion.xml.

HttpContext.Current.Server.MapPath("~/App_Data/navegacion.xml")
Manticore