{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/3036","labels_url":"https://api.github.com/repos/aspnet/Mvc/issues/3036/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/Mvc/issues/3036/comments","events_url":"https://api.github.com/repos/aspnet/Mvc/issues/3036/events","html_url":"https://github.com/aspnet/Mvc/issues/3036","id":103092135,"number":3036,"title":"Discussion: HTML5 defined elements with URL accepting attributes are now TagHelpers.","user":{"login":"NTaylorMullen","id":2008729,"avatar_url":"https://avatars.githubusercontent.com/u/2008729?v=3","gravatar_id":"","url":"https://api.github.com/users/NTaylorMullen","html_url":"https://github.com/NTaylorMullen","followers_url":"https://api.github.com/users/NTaylorMullen/followers","following_url":"https://api.github.com/users/NTaylorMullen/following{/other_user}","gists_url":"https://api.github.com/users/NTaylorMullen/gists{/gist_id}","starred_url":"https://api.github.com/users/NTaylorMullen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NTaylorMullen/subscriptions","organizations_url":"https://api.github.com/users/NTaylorMullen/orgs","repos_url":"https://api.github.com/users/NTaylorMullen/repos","events_url":"https://api.github.com/users/NTaylorMullen/events{/privacy}","received_events_url":"https://api.github.com/users/NTaylorMullen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-08-25T18:52:38Z","updated_at":"2015-08-25T22:10:27Z","closed_at":null,"body":"What's the Problem?\r\n-------------\r\nClassic Razor would resolve the value of **any** HTML attribute that started with `~/` as an application relative URL. This led to some invalid scenarios where users would provide attribute values such as `~/folder/file.txt` and get inaccurate URL resolutions. In addition, this feature couldn't be easily disabled.\r\n\r\nThe Fix\r\n-------------\r\nThere were multiple locations for a valid fix; we decided that it didn't make sense to hard code the list of HTML5 defined element/attribute combos in the core Razor parser. In addition, the introduction of `TagHelper`s led to some users expecting to see the raw value of their attribute values instead of the intercepted value.\r\n\r\nTherefore, we decided to create the [UrlResolutionTagHelper] (https://github.com/aspnet/Mvc/blob/f116b91750ee52ab54f39db5390d72037d26c524/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs) to take over `~/` resolution.\r\n\r\nIt targets the following attribute/element combos:\r\n- href : `<a>`, `<area>`, `<link>`, `<base>`\r\n- src : `<audio>`, `<embed>`, `<iframe>`, `<img>`, `<input>`, `<script>`, `<source>`, `<track>`, `<video>`\r\n- action : `<form>`\r\n- cite : `<blockquote>`, `<del>`, `<ins>`, `<q>`\r\n- data : `<object>`\r\n- formaction : `<button>`, `<input>`\r\n- icon : `<menuitem>`\r\n- itemid : everything\r\n- manifest : `<html>`\r\n- poster : `<video>`\r\n- srcset : `<img>`, `<source>`\r\n- archive : `<object>`, `<applet>`\r\n\r\nSide effects\r\n-------------\r\nAny element that the `UrlResolutionTagHelper` targets now have runtime `TagHelper` restrictions applied to them. Some of these restrictions are:\r\n\r\n- Depending on the targets `TagStructure` a tag targeted by the `UrlResolutionTagHelper` may result in an error based on supported syntax. \r\n    - `TagStructure.WithoutEndTag` = `<tag>` OR `<tag />`\r\n    - `TagStructure.NormalOrSelfClosing` = `<tag></tag>` OR `<tag />`\r\n    - `TagStructure.Unspecified` = Usually same behavior as `TagStructure.NormalOrSelfClosing` unless another `TagHelper` defines a different `TagStructure`.\r\n- C# must not exist in the declaration area of the tag.\r\n    - Invalid: `<a href=\"...\" @myClass>...</a>`\r\n    - Valid: `<a href=\"...\" class=@myClass>...</a>`\r\n- `TagHelper`s that bind URL based attribute values must now resolve them manually.\r\n    - Can be done by taking in the `IUrlHelper` in the constructor (from DI) and calling `IUrlHelper.Content` on the value.\r\n\r\n**Note:** These restrictions do not show up during design time due to the [editor browsable attribute](https://github.com/aspnet/Mvc/blob/f116b91750ee52ab54f39db5390d72037d26c524/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs#L49) on `UrlResolutionTagHelper`. Reason  behind this decision was that the majority of users will never encounter any of these restrictions and the `TagHelper` tooling would be misleading.\r\n\r\nWorkarounds\r\n-------------\r\n**Disable URL resolution on the page:**  \r\nBy default every page essentially has an:\r\n `@addTagHelper \"Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNet.Mvc.Razor\"`\r\n\r\nTherefore, to disable `~/` URL resolution for an entire page you can do:\r\n`@removeTagHelper \"Microsoft.AspNet.Mvc.Razor.TagHelpers.UrlResolutionTagHelper, Microsoft.AspNet.Mvc.Razor\"`\r\nThis can be done on the page and there's an [issue] (https://github.com/aspnet/Mvc/issues/2989) tracking the ability to do this in `_ViewImports.cshtml`.\r\n\r\n**Disable URL resolution on an element:**  \r\nYou can also disable the URL resolution capability on a per-element basis via the `TagHelper` opt-out character `!`: `<!href href=\"~/...\" @myAttribute>...</a>`"},"comment":{"url":"https://api.github.com/repos/aspnet/Mvc/issues/comments/134756861","html_url":"https://github.com/aspnet/Mvc/issues/3036#issuecomment-134756861","issue_url":"https://api.github.com/repos/aspnet/Mvc/issues/3036","id":134756861,"user":{"login":"michaldudak","id":4696105,"avatar_url":"https://avatars.githubusercontent.com/u/4696105?v=3","gravatar_id":"","url":"https://api.github.com/users/michaldudak","html_url":"https://github.com/michaldudak","followers_url":"https://api.github.com/users/michaldudak/followers","following_url":"https://api.github.com/users/michaldudak/following{/other_user}","gists_url":"https://api.github.com/users/michaldudak/gists{/gist_id}","starred_url":"https://api.github.com/users/michaldudak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaldudak/subscriptions","organizations_url":"https://api.github.com/users/michaldudak/orgs","repos_url":"https://api.github.com/users/michaldudak/repos","events_url":"https://api.github.com/users/michaldudak/events{/privacy}","received_events_url":"https://api.github.com/users/michaldudak/received_events","type":"User","site_admin":false},"created_at":"2015-08-25T22:10:27Z","updated_at":"2015-08-25T22:10:27Z","body":"Don't you think it may be confusing for developers to see that ~ behaves differently depending on the attribute it's used in? I personally would like it on by default with a possibility tu turn it off (or to escape the ~ character). This would be more consistent, I guess."}}