Solved

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

Posted on 2003-11-04
4
2,714 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
  • 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

839 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