Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Add URL resolving TagHelper to replace Razor ~/ functionality. #2807

Closed
NTaylorMullen opened this issue Jul 10, 2015 · 4 comments
Closed

Add URL resolving TagHelper to replace Razor ~/ functionality. #2807

NTaylorMullen opened this issue Jul 10, 2015 · 4 comments

Comments

@NTaylorMullen
Copy link
Contributor

This is in reaction to the conversation: aspnet/Razor#427 (comment)

Today Razor special cases ~/ at the beginning of attributes and treats them as "resolve an application relative URL"; however, it does this for every attribute which is overkill/incorrect. After investigating the attributes that have URL capability in Razor the list warrants something less hard coded into the core of Razor to resolve application relative URLs.

The list of HTML5 url based attributes I was able to find are:

  • href : <a>, <area>, <link>, <base>
  • src : <audio>, <embed>, <iframe>, <img>, <input>, <script>, <source>, <track>, <video>
  • action : <form>
  • cite : <blockquote>, <del>, <ins>, <q>
  • data : <object>
  • formaction : <button>, <input>
  • icon : <menuitem>
  • itemid : everything
  • manifest : <html>
  • poster : <video>
  • archive : <object>, <applet>

The TagHelper should exist in Microsoft.AspNet.Mvc.Razor and should be auto-added to Razor pages (much like how we auto add @inject directives). It should inspect TagHelperOutput.Attributes and TagHelperOutput.TagName for the various combinations listed above and resolve URLs if they begin with ~/. Lastly, it should have an [EditorBrowsable(EditorBrowsableState.Never)] attribute to prevent excess highlighting in the Razor editor (will work once aspnet/Razor#447 is completed).

@Bartmax
Copy link

Bartmax commented Jul 22, 2015

One question, about data attributes? I may want to do data-bigImageSource="~/Images/big/" In this case I should use data-bigImageSource="@Url.Content("~/images/big/")" ?

@NTaylorMullen
Copy link
Contributor Author

Correct.

@Bartmax
Copy link

Bartmax commented Jul 22, 2015

👍 thank you.

NTaylorMullen added a commit that referenced this issue Jul 28, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
NTaylorMullen added a commit that referenced this issue Jul 28, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
NTaylorMullen added a commit that referenced this issue Jul 30, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
NTaylorMullen added a commit that referenced this issue Aug 3, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
NTaylorMullen added a commit that referenced this issue Aug 3, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
NTaylorMullen added a commit that referenced this issue Aug 3, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
NTaylorMullen added a commit that referenced this issue Aug 3, 2015
- Razor removed the ability to automatically resolve URLs prefixed with `~/`; therefore `ScriptTagHelper`, `LinkTagHelper` and `ImageTagHelper` have changed to take in `IUrlHelper`s and auto-resolve their URL based properties if they start with `~/`.
- Added a catch-all `~/` resolver for non `TagHelper` based HTML elements. Razor used to resolve any attribute value that started with `~/` now the behavior is restricted to attributes that can contain URLs.
- Updated `IUrlHelper` to accept `null` values.
- Added functional tests to validate that URLs resolve correctly.
- Updated `TagHelper` tests to ensure that URLs are resolved via an `IUrlHelper`.

#2807
@NTaylorMullen
Copy link
Contributor Author

0ef68ee

@NTaylorMullen NTaylorMullen changed the title Add URL resolving TagHelper to replace Razor ~ functionality. Add URL resolving TagHelper to replace Razor ~/ functionality. Aug 24, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants