vikifor
vikifor

Reputation: 3466

On which port my web application is running asp.net C#

Is there a way to find out on which port my web application is running using C# code as I like to write it in integer variable?

Upvotes: 5

Views: 6116

Answers (3)

HatSoft
HatSoft

Reputation: 11191

If you running from Visual Studio then every time it will pick up a new port number, once you have deployed your application then it will pick up the port given for your website.

The default port is 80.

Upvotes: 2

Adil
Adil

Reputation: 148110

You can get it this way, MSDN, If you could not see port in url it means the port is 80.

int port =  Request.Url.Port;

or you can get from url

Uri uri = new Uri("http://www.mywebsite.com:80/pages/page1.aspx");
int port  = uri.Port;

Upvotes: 3

burning_LEGION
burning_LEGION

Reputation: 13450

You can choose the port in project settings if you use Visual Studio Development Server or choose the port in IIS settings.

Upvotes: 1

Related Questions