Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All

"System.Web.HttpContext.Current.Request.Url.Authority" is giving me something like "0.0.0.0:4551" for "http://localhost:4551/WebApplication"

any pointers why i am getting 0.0.0.0 and not localhost ??

Best Regards,
Zain ul Abideen

UPDATE:
OP was able to resolve the issue himself. Posted as an answer.
Posted
Updated 26-Jan-11 4:45am
v2

Do not use the Authority, but use the Host

Request.Url.Host

The authority search back on dns, the host get the site from the url.
When you search the dns you get the first name of your ip address that you have connected with that name and not all names.
 
Share this answer
 
Comments
Phan7om 26-Jan-11 6:33am    
Hi Zahra
i have tried using Host but it's giving me the same 0.0.0.0 value and no port number this time :(

Regards
Phan7om
Ryan Zahra 26-Jan-11 6:46am    
I'm using the following code:

string url = System.Web.HttpContext.Current.Request.Url.Authority;
After the line of code executes, the variable url holds the following: "localhost:64848"

string host = System.Web.HttpContext.Current.Request.Url.Host;
After the line of code executes, the variable host holds the following: "localhost"

Can you please show me your code.
Phan7om 26-Jan-11 6:54am    
here is my code
url = @"http://" + System.Web.HttpContext.Current.Request.Url.Host + System.Web.HttpContext.Current.Request.ApplicationPath + @"/Default2.aspx" + "?accNo=" + accountNo;

and after executing this line url holds the following value:
http://0.0.0.0/WebApplication/Default2.aspx?accNo=3333333333333

whereas the url in the browser is:
http://localhost:4551/WebApplication/Registration/NewRegistration.aspx
Ryan Zahra 26-Jan-11 7:00am    
what do you see when you type "http://localhost" in your browser?
Also, if you navigate to "http://0.0.0.0/WebApplication/Default2.aspx?accNo=3333333333333" does the web page load?
Phan7om 26-Jan-11 7:05am    
sorry for wrong response

if i navigate to http://0.0.0.0:4551/WebApplication/Default2.aspx?accNo=3333333333333, firefox says website not found and if i replace 0.0.0.0 with localhost/127.0.0.1, I get the correct response
Couldn't find the main culprit, but restarting VS (all its instances) and changing the port of the web development server may help

Regards,
Zain ul Abideen
 
Share this answer
 
Comments
Ryan Zahra 26-Jan-11 8:24am    
That's very strange indeed. At least you've got it working :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900