Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

726 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