-
Notifications
You must be signed in to change notification settings - Fork 2.1k
UrlResolutionTagHelper+EncodeFirstSegmentContent net::ERR_ABORTED #7700
Comments
@AHHejazi, can you please share your code here? We will need a repro to investigate. |
Dear we upload the project on github https://github.com/AHHejazi/IdentityV1/tree/master/MOHIdentityApp the main project is : Identity.WebApp the Tagehelper project under Common/Framework.Web/ when you run the project you will get home page => right click and inspect =>in console you will get the error : GET http://localhost:61233/Microsoft.AspNetCore.Mvc.Razor.TagHelpers.UrlResolutionTagHelper+EncodeFirstSegmentContent net::ERR_ABORTED this error appear when we include the taghelper @addTagHelper Framework.Web.TagHelpers, Framework.Web* in _ViewImports.cshtml but if i remove this line the the errors gone but the custom tag helpers will not work,thank in advance |
@NTaylorMullen, reassigning this to you to investigate. Thanks! |
@AHHejazi really appreciate the repo, worked first try, no problems at all! So the issue you're encountering is actually in how your using System;
using System.IO;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace Framework.Web.TagHelpers
{
// You may need to install the Microsoft.AspNetCore.Razor.Runtime package into your project
[HtmlTargetElement("script", Attributes = "src")]
public class ScriptTagHelper : TagHelper
{
private readonly IScriptManager _scriptManager;
public ScriptTagHelper(IScriptManager scriptManager, HtmlEncoder htmlEncoder)
{
_scriptManager = scriptManager;
HtmlEncoder = htmlEncoder;
}
public string IncludeOrderPriority { get; set; }
private HtmlEncoder HtmlEncoder { get; }
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
// needed because of builtin tag helper that looks at src
var src = GetEncodedStringValue(output.Attributes["src"].Value);
_scriptManager.AddScript(new ScriptReference(src, Convert.ToInt32(IncludeOrderPriority)));
await output.GetChildContentAsync();
output.SuppressOutput();
}
private string GetEncodedStringValue(object attributeValue)
{
var stringValue = attributeValue as string;
if (stringValue != null)
{
var encodedStringValue = HtmlEncoder.Encode(stringValue);
return encodedStringValue;
}
else
{
var htmlContent = attributeValue as IHtmlContent;
if (htmlContent != null)
{
var htmlString = htmlContent as HtmlString;
if (htmlString != null)
{
// No need for a StringWriter in this case.
stringValue = htmlString.ToString();
}
else
{
using (var writer = new StringWriter())
{
htmlContent.WriteTo(writer, HtmlEncoder);
stringValue = writer.ToString();
}
}
return stringValue;
}
}
return attributeValue.ToString();
}
}
} Note: After this fix there still seems to be an issue with nToastNotify not being defined but i'll leave you to figure that one out 😉 |
Thank you too much |
Dears, we have this issue with MVC Core
https://stackoverflow.com/questions/49971207/urlresolutiontaghelperencodefirstsegmentcontent-neterr-aborted Please any help
The text was updated successfully, but these errors were encountered: