?
Solved

How to get: Request.ApplicationPath & Request.Url.GetLeftPart

Posted on 2003-11-04
4
Medium Priority
?
2,757 Views
Last Modified: 2012-06-27
I'm new to client-side Java scripting ... that said .... I use C# in CodeBehind, I get the ASP .NET application path using the following code.

   string mRootPath = Request.ApplicationPath;
   if (mRootPath.Substring(mRootPath.Length-1, 1) == "/")
   {
      mRootPath = mRootPath.Substring(1, mRootPath.Length-1);
   }
   string mPath = Request.Url.GetLeftPart(UriPartial.Authority) + mRootPath + "/";

Resulting in mPath equal to ...
   during development>  http://localhost/MyApp/
   once deployed>       http://MySite.com/

I need to get the same information on the Client-Side using Java Script.
Possible?
0
Comment
Question by:volking
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 9679982
<script language=javascript>
  var jsRootPath = "<%= mRootPath %>";
</script>
0
 
LVL 33

Expert Comment

by:knightEknight
ID: 9679986
can you just do this?

<SCRIPT>
  var mPath = "<%=mPath%>";  // create a client string from the server string
</SCRIPT>
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 2000 total points
ID: 9680012
or if you just want to get the path from javascript:

<script language=javascript>
   var jsRootPath = window.location;
   
   // strip everything after the last occurance of '/'
   jsRootPath = jsRootPath.substring(0, jsRootPath.lastIndexOf("/"));
</script>
0
 

Expert Comment

by:profit11
ID: 10282598
the accepted answer causes an error unless "href" is used:

var jsRootPath = window.location.href;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question