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 Answer 1

2

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.