473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

how do you get the context path in the web app?

I'm trying to reference images in my webapp. I'm coming from j2ee and I
just write a small jsp scriplet that says to go grab the context path. How
do I do that with C#? If it's done differently in C#/.NET, please set me
straight (please be gentle :>).

If my current setup is this
+References
+Dilbert.jpg
Default.aspx
+Searching
+Default.aspx

In the /Searching/Default.aspx, I know I can reference the Dilbert.jpg image
using relative references
.../References/Dilbert.jpg

But how do I do it with absolute references? When I try this
/References/Dilbert.jpg
It is using the References as the webapp name. How can I pull the context
path (including port change if not default port 80)?

Thanks.
Nov 18 '05 #1
5 5914
Hello Flip,

Use the ~ in your server controls. ~ or Page.ResolveUrl("~/References/Dilbert.jpg")
will work from any level in your heirarchy. The ~ translates to the application
root.

--
Matt Berther
http://www.mattberther.com
I'm trying to reference images in my webapp. I'm coming from j2ee and
I just write a small jsp scriplet that says to go grab the context
path. How do I do that with C#? If it's done differently in C#/.NET,
please set me straight (please be gentle :>).

If my current setup is this
+References
+Dilbert.jpg
Default.aspx
+Searching
+Default.aspx
In the /Searching/Default.aspx, I know I can reference the Dilbert.jpg
image
using relative references
.../References/Dilbert.jpg
But how do I do it with absolute references? When I try this
/References/Dilbert.jpg
It is using the References as the webapp name. How can I pull the
context
path (including port change if not default port 80)?
Thanks.

Nov 18 '05 #2
Howdy Matt. Thank you for the reply.
"Matt Berther" <mb******@hotmail.com> wrote in message
news:59***********************@news.microsoft.com. ..
Hello Flip, In case you were wondering, Flip's the nickname as my car was flipped over
onto it's roof one morning. :< but :> at the sametime. Just in case you
thought the posting was a hack.
Use the ~ in your server controls. ~ or Page.ResolveUrl("~/References/Dilbert.jpg") will work from any level in your heirarchy. The ~ translates to the application root.

When I read your email the first time, I thought the tilde was a mistype,
but when I got to your last sentence I realized you were serious! I have to
read up on that. Do you happen to have any MSDN links about this? If it's
easy to google, then no need for the MSDN link, I'll find it, but I didn't
have much luck with googling asp.net and "context path".

Thanks again! :>
Nov 18 '05 #3
> Use the ~ in your server controls. ~ or
Page.ResolveUrl("~/References/Dilbert.jpg")
will work from any level in your heirarchy. The ~ translates to the

application

Now that I have the right keywords to google this! :> I found some good
info.
http://www.aspnetpro.com/newslettera...200311kd_l.asp

What other key characters are there in c# and .NET I can use and abuse? :>
Nov 18 '05 #4
Hello Flip,

Glad you found it... ~ is one of the best things about ASP.NET. :=)

--
Matt Berther
http://www.mattberther.com
Use the ~ in your server controls. ~ or

Page.ResolveUrl("~/References/Dilbert.jpg")
will work from any level in your heirarchy. The ~ translates to the

application

Now that I have the right keywords to google this! :> I found some
good info.
http://www.aspnetpro.com/newslettera...0311kd_l/asp20
0311kd_l.asp

What other key characters are there in c# and .NET I can use and
abuse? :>

Nov 18 '05 #5
> Glad you found it... ~ is one of the best things about ASP.NET. :=)
I just realized something when trying this out. The control has to be a
runat="server". Just a caveat if someone new is watching this thread.
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: SPG | last post by:
Hi, I am relatively new to TOMCAT, and am trying to deploy a web app using it. I have a domain name that I want to use to access my web app directly. By default, I deploy my WAR, and it deploys...
0
by: Srini | last post by:
I am implementing Front Controller in ASP.net as outlined in Microsoft documentation titled "Implementing Front Controller in ASP.NET Using HTTPHandler"...
13
by: William Stacey | last post by:
Using the following code sample: public byte Get() { // <= Possible to switch Here?? lock(syncLock) { //Do something in Get(). } }
5
by: Dean L. Howen | last post by:
Dear friends, Could we determine when context menu should appear?
2
by: Mauricio | last post by:
Hi! I´m using a custom handler with an ASP.NET application using the Front Controller pattern. But I´m experiementing some problems with the following line of code: ...
5
by: | last post by:
Hoping someone can help with a simple but puzzling problem. I have some code that I want to build as a class method. The code works fine when I embed it in Page_Load. But when I try to generalize...
1
by: Debs | last post by:
Hi, I am running my website using Weblogic, so the path is something like http://<myip>:<port>/<servername>/ On JSP pages I can use <%=request.getContextPath()%to get the root path of the...
0
by: Andrew2 | last post by:
Sorry guy for the (probably) stupid question, but reading and testing the second overload of the Context.RewritePath, that one with the rebaseClientPath param. Msdn says: true to reset the...
0
by: philaphan80 | last post by:
I'm hoping someone can offer some guidance regarding a concept I have. I'm trying to perform the following within Windows Explorer: 1. Add an entry to the context menu which should be executed...
0
by: SunkenHeights | last post by:
Hi people. Can anyone please tell me how to write into an xml given the context path? I am able to write into the xml given the physical path but when I pass the context path a TransformerException...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.