-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Make it easy to configure a host/scheme for absolute URLs with LinkGenerator #14192
Copy link
Copy link
Open
Open
Copy link
Labels
affected-fewThis issue impacts only small number of customersThis issue impacts only small number of customersarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-routingseverity-minorThis label is used by an internal toolThis label is used by an internal tool
Milestone
Metadata
Metadata
Assignees
Labels
affected-fewThis issue impacts only small number of customersThis issue impacts only small number of customersarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing oneThis issue represents an ask for new feature or an enhancement to an existing onefeature-routingseverity-minorThis label is used by an internal toolThis label is used by an internal tool
Type
Fields
Give feedbackNo fields configured for Feature.
Is your feature request related to a problem? Please describe.
LinkGenerator
LinkGeneratorrequires theHttpContextto generate a full absolute URL which also contains the scheme, hostname and optional port. Outside of the controller, this means I have to also inject theIHttpContextAccessorinto my constructor and pass it in like so:This requires a lot of ceremony and additional noise.
IUrlHelper
IUrlHelperdoes not require theHttpContextif you add this code to theStartup. We use theIActionContextAccessorandIUrlHelperFactoryto registerIUrlHelperinto the IoC container.Then if you use the following extension method to create your URL's:
Here is the usage:
I think you'll agree this is much nicer.
Describe the solution you'd like
I would like a way to generate URL's without having to inject the
IHttpContextAccessorandLinkGeneratorjust to generate a single URL. Or a way to useIUrlHelperwithout all the setup code to get it working nicely.