Asp.net tips: getting rid of Path Problems (1)

Source: Internet
Author: User

When programming in Asp.net,
Image files and style sheets are often referenced.
Generally, because your Aspx is in various folders at different levels,
Therefore, the reference to the same file is often changed
Href = ".../../CSS/style.css"
Href = ".../../CSS/style.css"
And so on,
Each time a reference is added, the number of levels in the directory is required,
It is painful.
In fact,
There is a simple way to solve this problem at one time:
1. Add the images and CSS folders to the project root directory,
And transfer the corresponding file
2. Add a new site (such as helloworld) to IIS ),
This site points to your Asp.net project,
The site has a custom port, such as 9998.
3. Now, all references to images and style sheets can be written as follows:
/CSS/style.css
/CSS/admin.css
/Images/logo.gif
/Images/submit.gif
That is, the referenced style sheets and images are stored in the CSS and imges folders in the root directory,
Instead of using a lot of ../to indicate the path.
Now, your style sheets and images can take effect at runtime (http: // localhost: 9998,
However, images and style sheets cannot be found in the development environment.
4. Modify the projectname. csproj. webinfo file of the project,
Change urlpath to http: // localhost: 9998/projectname. csproj
Congratulations! Now, your style sheets and images can take effect in the development environment!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.