Friendly URLs for localhost ASP.NET websites - asp.net

I Use Visual Studio 2010 with ASP.NET 4.0 and IIS7.
When I open my site, the URL looks like this
http://localhost:6549/Website/help/tab/contact-us
I want a friendly URL:
http://mysite/help/tab/contact-us
or anything that will help me to get rid of the Port 6549 from URL
http://localhost/Website/help/tab/contact-us
I use ASP.NET Development Server which is what Visual Studio use when you run a localhost website
Wait !! Please make distinction between "Properties window" and "Property pages" of the project. I always tried your advices, but using "Property pages", and there is no such property like Use dynamic ports on that page. This property can be found only in the "Properties window"

Assuming it's the ASP.NET development server:
To get rid of the port number you need to do this
- go to properties of the project
- click the web tab
- check the specific port and assign 80
There is also a virtual path setting here which you could set to /

Is your solution configured to use IIS and not the ASP.NET Development Server? There is also a property on the web application where you can specify the port (or allow for a random port to be chosen) - port 80 is the appropriate port - this requires administrator access to the process that is launching the web site.

Edit:
I was thinking you can use your host file to redirect the user, but I checked and you can't redirect to a port.
If you have IIS7 on the machine, just make the location of your web development folder into a virtual directory on IIS.
Then you can access it by http://localhost/website/

Related

How to configure IIS 7 for localhost website?

I am new in Asp.Net
I have enabled features of IIS 7 on my windows system and able to see IIS manager.
I created an application but build/run application through visual studio it goes to browser and run the application with different port number. When i stop build/run application through visual studio and again i refresh browser application could not run.
I want to run application without visual studio. How to do this.
It gives this : http://localhost:9864/
To configure IIS with a new website follow these instructions:
Open IIS manager, right click Sites (At the right menu) and click Add Website
Give the site a Site Name, The physical path on your machine, and a Host Name
There are some conventions as for what website physical path to choose you can read about it in this SO question
In Windows Explorer go to C:\Windows\System32\drivers\etc and Edit the hosts file
Add this line at the end of the file:
127.0.0.1 your-chosen-host-name-from-iis-ie-localhost.testsite.com
And save the file
Thats about it. You can open your browser and browse the Host Name you chosen for your website or in IIS right click your site and click Manage Website - Browse
Important note
If you wish to use the same address as your VS uses (http://localhost:9864/) then on step 2 leave the Host Name textbox blank and instead change the Port textbox to your desired port (9864). In this case you can also ignore step 3.
As a site note:
If you installed IIS on your machine after the VS installation you might get some conflicts. You might be able by this stage to browse to static content as html but not .NET resources like aspx files. If by browsing to .NET files you get a message saying The page you are requesting cannot be served because of the extension configuration you can solve it with this SO question

IIS ASP.NET MVC3 doesn't show my website

So I've set up IIS 7.5 to host my ASP.NET MVC website on my own local machine, but when I surf to http://localhost/ I just get this:
Welcome to ASP.NET MVC!
To learn more about ASP.NET MVC visit
http://asp.net/mvc.
A very basic HTML page with only this on it. No CSS or anything.
I haven't used IIS before, so I don't know what settings I need to change in order for this to work, but this is what I've done:
Added a new Site "MySite"
Set the Physical path to the root folder of my asp.net project
Tested the settings (everything OK)
Edited the "MySite" Application Pool and set it to .NET framework version v4.0.30319
What else do I need to do to make my website display? Thanks.
EDIT: please read this
I'll give a step-by-step walkthrough of what exactly I do:
1) I create a new ASP.NET MVC3 Razor web project. I don't do anyting but save and build the project.
2) I open IIS Manager
3) I go to Sites -> Add Web Site
4) I fill in following data:
Site Name: MyWebSite
Application Pool: MyWebSite
Physical Path: Visual Studio 2010\Projects\MyOwnProject\MyOwnProject (Project root folder)
Connect as: My PC's login and password. Test Settings is succesful
I leave the rest of the settings as it is and press OK
5) I go the Application Pools and edit the basic settings of MyWebSite to change the .NET framework to the latest version (v4.0.30319)
6) I select MyWebSite and click Browse *:80 (http) to go the web site. It opens up Chrome and I see the following page:
<h2>Welcome to ASP.NET MVC!</h2>
<p>
To learn more about ASP.NET MVC visit http://asp.net/mvc.
</p>
That's it. Nothing more. What am I missing here?
That looks like it is working (at least that's an MVC page it is displaying.) Maybe you need to alter your default route in Global.asax.cs to hit a different controller?
Do you have a Layout.cshtml in your shared folder and is your ViewStart pointing to it?
Edit:
I do remember having an issue like this at one point. I think it has to do with static resources pointing to the root which by default will be pointing to another App in IIS. I'm not sure if this is exactly the issue but what I do is setup an address in my host file for each application. For me the host file is :
C:\Windows\System32\drivers\etc\hosts
You have to run notepad or something as Administrator to edit it and add the following line:
127.0.0.1 MySite
This will allow you to simply navigate to http://mysite without any conflicts. Just double check your IIS setting so that the hostfile address point to the right physical path.
It seems I've fixed it, I don't know how or why this works. But this is what I've done:
In Visual Studio, I went to the Properties of my project. There, in the Web tab, I selected "Use local IIS Web Server", filled in "http://localhost/MyWebSite" and hit "Create Virtual Folder".
Save and build the project and suddenly it worked. However, I am not able to debug my project from Visual Studio now. But when I change the Web configuration back to "Use Visual Studio Development Server" it still works and I can debug again...
Doesn't make too much sense because you should be able to debug from IIS right?

asp.net setting up subdomain on localhost

I added the following entries in the HOSTS file.
127.0.0.1 abc.localhost.com
127.0.0.1 xyz.localhost.com
Using the VS2010 ASP.NET Development server I am unable to run or execute the website.
When browsing http://localhost:2687/TestProject/ it shows up the default.aspx page. But when accessing http://abc.localhost:2687/TestProject/ it shows a website cannot be found page.
Is there anything else to be done when setting up subdomain on localhost.
EDIT: To make this work I removed the .com and in IE-->Connections-->LAN uncheck everything. Subdomains with port works are correctly getting forwarded. Nothing else need to be configured.
Obvious mistake is that in your hosts file you have abc.localhost.com, whereas you are browsing to http://abc.localhost/folder
Not the same thing.
Not sure this will work as you intend anyhow. I would also recommend IIS Express, part of WebMatrix, which I think is still in beta, or just use IIS. IIS 7+ on Vista, W7, Server 2008 is all really easy to use.
Use IIS or IIS express, rather than Cassini. (For several reasons, which you can google or look for on stackoverflow)
With the IIS you can easily add a hostheader entry to you webapplication with just 2 clicks.
Be aware, that you are assigning both a Url and a port.
So adding abc.localhost won't allow you to browse abc.localhost2687, just the default port (80). If you also want to browse to abc.localhost:2687 you need to a a hostheader entry according to that that Url and port.
This screenshot shows you the dialog to add hostheaders (the picture is from IIS 6, but in IIS 7 or IIS 7.5 it looks very similar)

Get Visual Studios to use subdomain?

While writing an asp.net project i may have this url for testing/debugging
http://localhost:1234/
I have code that takes in account of subdomains. Can i make visual studios call the same code with
http://anysub.localhost:1234/
You can update your hosts file and put in any subdomin for the localhost:
127.0.0.1 example.com
127.0.0.1 sub.example.com
You can then point your browser to either domain. So long as the debugger is attached to IIS/Dev browser, you will be able debug your server side code.

Run ASP.NET application as Default Web Site on dev machine

I am trying to run my ASP.NET Web Application Project in my Local IIS Web Server instead of using the Visual Studio Development Server. It seems to only allow me to run my application in a Virtual Directory off of the Default Web Site. However, I would like to run the application in the root of the Default Web Site itself.
I go into the properties of my project, go to the Web tab, click the User Local IIS Web server radio box, and change the Project URL to http://localhost/. However, when I attempt to save, it tells me I need to configure the Virtual Directory, although I am not using a Virtual Directory.
Has anybody made this work before? Thanks!!
It sounds like localhost port 80 is already in use.
IIS creates a default web site that listens on localhost port 80. Have you disabled that before trying to add yours?
Another approach is to have your site listen on a different port, 81 for example.
So far I used a Post-Build event to copy the contents of my project to c:\inetpub\wwwroot\ and I set the Start Action's Start URL to http://localhost/. Not very elegant, but it gets the job done. I would love for somebody to include a more elegant solution.

Resources