How do you get an ASP.NET application relative URL from JavaScript?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You could always generate a set of constants for paths that you will be using in a way which Javascript can see. ex:
Of course, you can adapt this to your app’s needs. For example, it might not be a bad idea to stick the initial declaration of Paths in a common js file, and have a method in your master page to add paths you will definitely need on each page. Subpages can generate paths as needed, possibly from a helper method of some sort that generalizes the whole process.
edit: I’ve been thinking about this some more. Here’s a possible implementation, completely untested and probably not exactly right:
and in your page: