ASP. NET startkit timetracker (processing notes of Application Path)

Source: Internet
Author: User

During developmentProgramThe directory structure is clear. We hope that many different file directories will be created.
For example, the structure is as follows:

| Root
| PIC
| Web
| Usercontrol

In the web directory, how do we get the image path in the PIC directory?

Method 1:
Let's first look at the solution of ASP. NET startkit timetracker:
The global class of ASP. NET startkit timetracker defines a public method:

Public   Static   String Getapplicationpath (httprequest request)
{
String Path =   String . Empty;
Try
{
If(Request. applicationpath! = "/")
Path=Request. applicationpath;
}
Catch (Exception E)
{
ThrowE;
}
Return Path;
}

Make a call as needed, for example:
<A href = '<% = Global. getapplicationpath (request) %>/<% # (ASPnet. starterkit. timetracker. businesslogiclayer. tabitem)

Container. dataitem). PATH %> '>
<% # (ASPnet. starterkit. timetracker. businesslogiclayer. tabitem) container. dataitem). name %>
</A>

I modified this method:

I will first define a page base class.
Public class pagebase: system. Web. UI. Page
Let other aspx pages in the system inherit pagebase.

Attributes under the base class definition

Protected   String Apppath
{
Get
{
String Path = String. empty;
Try
{
If ( " / " ! = Request. applicationpath)
{
Path=Request. applicationpath;
}
}
Catch (Exception E)
{
ThrowE;
}
Return Path;
}
}

On the my ASPX page, bind the following attributes to get the image.
'>

Method 2:
It is also a common method.

<Asp: Image id = "image1" runat = "server" imageurl = "../PIC/register.gif"> </ASP: Image>

In fact, the server control supports another path Representation Method :"~ ", Equivalent to httprequest. applicationpath
<Asp: Image runat = "server" id = "image1" imageurl = "~ /PIC/register.gif "> </ASP: Image>

Non-server controls can also be like this:

Method 3:
The path is saved in Web. config during deployment on your machine. Then, the image path is determined in the background. CS using configuration. paiettings.
This method is the worst.

Summary: I personally think that method 1 is the best and most flexible. It is also the most used method I have seen in many Microsoft examples.
I don't know if there are other methods. Please kindly advise.

Related Article

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.