Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4053468
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:27:03+00:00 2026-05-20T14:27:03+00:00

Let’s say that I have my ASP.NET web application in a directory called MyApp

  • 0

Let’s say that I have my ASP.NET web application in a directory called “MyApp” both locally and on a remote server. I’m trying to build an onclick response to a link. The response calls a Javascript function, passing it the URL of an .aspx page in my web app. The Javascript pops out a new window displaying the page. My C# code looks like this:

link = new HyperLink();
link.Text = product_num_str;
link.NavigateUrl = "#";

string url = "Javascript:My_NewWindow('http://" + 
             HttpContext.Current.Request.Url.Authority +
             "/ProductInfo.aspx?_num=" + product_num_str + "')";

link.Attributes.Add("onclick", url);

I started using the Request’s Authority property because I was having problems running locally on the Visual Studio web server when I used the Host property. The problem was that Host only returned “localhost” instead of the host and port number.

When tested locally, the code works because the “authority” maps to my app root folder. The URL generated is, e.g.,

http://localhost:52071/ProductInfo.aspx?_num=123

If I run on a remote server, however, I end up with something like:

http://company-server/ProductInfo.aspx?_num=123

This fails to find the page, because in this case the “MyApp” root folder must be included.

There is probably an easier way – putting an entry in the web.config or something. My motivation originally was to allow the app to be published to a folder of any name and work as is.

I could hack my approach and search the string for “localhost” or something, but that’s ugly. So how do I build a string that will work everywhere?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:27:04+00:00Added an answer on May 20, 2026 at 2:27 pm

    I’m assuming you’re doing this from within a Page or Control. If that’s the case you should do this instead:

    string fullUrl = this.ResolveClientUrl("~/ProductInfo.aspx?_num=" + product_num_str + ");
    

    That will give you the proper URL no matter where the application is deployed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have two assemblies: BusinessLogic and Web. BusinessLogic has an application setting
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say I have some text as follows: do this, do that, then this,
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's say you have a method that expects a numerical value as an argument.
Let's say I have a bunch of links that share a click event: <a
Let's say I have an facebook application running using the JS SDK. First user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.