Zahra
Zahra

Reputation: 7207

Local paths for the files are different from the paths on the server

We have changed the domain for our staging website and it turns out that the paths on the server are now pointing to the old paths which are no longer valid. I was wondering if there would have been a better way for us to do the paths at the begining so that we did not have to go through the whole website to fix the paths. The server paths were hard-coded!!

example:

name1.staging.com/somepath/file.css

is now changed to

name2.staging.com/name3/somepath/file.css

so all the paths that used to be like: /somepath/file.css

now need to be changed to /name3/somepath/file.css

Upvotes: 0

Views: 96

Answers (1)

Adrian Wragg
Adrian Wragg

Reputation: 7411

When you're writing an asp.net application, the most important path you need to be aware of is the following one:

    ~/

This will always return the root of the current application, whether you pass it to Response.Redirect(), Page.ResolveUrl() or use it as part of your hyperlink in an <asp:hyperlink /> tag. For example:

<link href='<%= Page.ResolveUrl("~/somepath/file.css") %>' rel='stylesheet' />

Note that this only works within code handled by .net itself; for other files, you need to ensure that you always use relative paths. So for example if you have the following structure for your images and css:

/
    /images
        logo.gif
    /css
        main.css

then you reference the logo using the style:

{
    background-image: url(../images/logo.gif);
}

Upvotes: 1

Related Questions