Starting in ASP.NET 3, it is also possible to restrict a route based on the host header and port. You can either do that through attributes or by using fluent (code-based) configuration.
Here's an example of using attributes:
[Host("localhost", "127.0.0.1")]
public IActionResult Local() { ... }
[Host("localhost:80")]
public IActionResult LocalPort80() { ... }
[Host(":8080")]
public IActionResult Port8080() { ... }
We have three examples of using the [Host] attribute here:
- The first one makes the Localaction method reachable only if the local header is localhost or 127.0.0.1; any number of host headers can be provided.
- The second example demands a combination of host header and port, in this case, 80.
- The final one just expects port 8080.
The [Host] attribute can, of course, be combined with any [Http*] or [Route] ones.
Here...