Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    anyone know if its possible to dynamically define the name of an html element in razor?
    Depending on how this component is called, sometimes it should be an anchor element, and sometimes a div. I am trying to avoid repeating a bunch of markup in there...
    MarkupString may be the thing you want there
    @* content *@
    @code {
      private MarkupString _openTag;
      private MarkupString _closeTag;
    interesting, ill check that out, thanks!

    @andrewleith An option would be this primitive component, where you can pass whatever html element you want through the HtmlTag property

    public class Element:ComponentBase
            [Parameter] public RenderFragment ChildContent { get; set; }
                                      public Dictionary<string, object> UserAttributes { get; set; } = new Dictionary<string, object>();
           protected  override void BuildRenderTree(RenderTreeBuilder builder)
                builder.OpenElement(0, HtmlTag);
                builder.AddMultipleAttributes(1, UserAttributes);
                builder.AddContent(2, ChildContent);

    So you can use it like

    <Element HtmlTag="div" class="my-class" > <div> Child Content</div> </Element>
    This renders like
    <div class="my-class"> <div> Child Content</div> </div>
    hey guys, has anyone experienced this? I have a premade class from an old WSDL file I have to use, I generated it. It has "Field" appended on the end of all the properties.... Reference_IDField etc ... When I return the object normally in a POST method it keeps the fields. However when serializing it with Json.Serializer it actually removes the "Field" from all the properties.
    how can I make it so returning the object also removes the "Field" part
    I've never seen this before, is this related to Text.Json.Serializer?
    Scott R. Frost
    Got a super weird one for you guys. We have a .NET 5 API app, running as a sub application as a folder under a .NET 4.x app in Windows Server 2016. It works, but only the first 4096 bytes of each response are being returned. It doesn't crash, it just hangs there forever after returning the first 4096 bytes of data. I've been searching for 2 hours trying to fix it, but it's a really weird case. Any ideas?
    Tomas Jurasek
    Hi guys, I'm playing with localized routes in the asp.net core MVC and I created package where you can localize your routes also with localized links in View.
    Feedback welcome - https://github.com/tomasjurasek/AspNetCore.Mvc.Routing.Localization

    my signalr hub gives 403 when I try to access wss://myurl.com/hub but it works well when I use https://myurl.com/hub
    anyone here can help or just explain why this is happening ?

    there is no Authorize attribute on my Hub so there is not authentication on hub url.

    do you cross posting each signalr question every time ?
    getting 6notifications for 2 questions is weird TBH
    Stefan Ossendorf
    Good morning everyone. I have a web-api action which returns a File (via File()). How do I annotate it properly so that swagger/openAPI gets it right and I can use it for code generation? Thanks in advance :)
    I am using asp.net boilerplate asp.net core mvc .net 5 . I got stuck in api when using a post, put and delete. anyone have experience this one? I got a 400 bad request response and I can't find any answers in google. :(
    I figured out never mind thanks
    Alberto Passalacqua
    Did you have ApiController annotation? 🤔
    Because antiforgery is only for mvc controllers (out of the box)
    I was running the wrong project instead of web.host, I started web.mvc. Right now, I don't see that error anymore
    Alberto Passalacqua
    oh... happens
    Hi I got 500 internal server error on my newly created table when inserting data using api in asp.net boilerplate and It doesn't have any error in output window. I can insert successfully on other default tables such as role and users.
    oh I forgot there is a log in the directory. dang
    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_SinkingGroup_AbpUsers_DeleterUserId". The conflict occurred in database "UtangGastosTigomDb", table "dbo.AbpUsers", column 'Id'.
    The statement has been terminated. <-- this is what I see in the logs.
    this is my service application
    it's all good now :)
    Calvin Dallmore
    is there a way to add middleware between the authorize attribute being evaluated and the controller action being called? I am trying to enrich my logs with the users identity, but its not evaluated until authorize is processed.
    if you use serilog add en enricher
    inject httpcontextaccessor
    and use context?.User and get the "sub" claim for example
    and use the tryAddProperty
    all your logs will have that property if the claim is set (so AFTER) authentication (don't mix it with authorization)
    I am wanting to serve an index.html static file from asp net core and have app.usedefaultfiles() and app.usestaticfiles() and it does work except is is getting there through a redirect 301 which is problematic with SEO. Is there something I could do about this?
    did anyone clone entity framework migration to other projects before?
    Ruben Rutten
    Hi, I'm working on a .NET Core 5 project where I have Tags and Projects. There's a many-to-many relationship between the two. modelBuilder.Entity<Project>().HasMany(p => p.Tags).WithMany(t => t.Projects); and that seems to work fine. Now, I want to add a new entity called ProjectTagHighlight, which need to have an Id, ProjectId, TagId and a text column. How do I set this up properly, because I don't have a ProjectTag model in my code
    Josua Jäger
    Hi, posted a question on SO about hosting blazor server side without razor. https://stackoverflow.com/questions/65617445/blazor-server-sider-without-razor
    Magnus Grindal Bakken

    This question isn't really ASP.NET Core-related, but I asked it a week ago in the corefx channel and no one answered:

    I have a System.Text.Json problem. I recently upgraded my API code to .NET 5, and I'm looking into converting the serialization provider from JSON.NET to System.Text.Json. Standard serialization/deserialization works fine, but I'm having trouble converting a particular pattern.

    In my API I have a few places where I distinguish between null inputs and undefined in the input JSON. Specifically, null means "remove this value" and undefined means "keep this value as it is".

    The way I've implemented this is with the approach described here: https://github.com/alberto-chiesa/SettableJsonProperties. I have a type Optional<T> which distinguishes between null and undefined, an OptionalJsonConverter which converts literal null properties to null and omitted properties to undefined, and a custom contract resolver that relies on the ShouldSerialize-metod, as described here: https://github.com/alberto-chiesa/SettableJsonProperties/blob/master/SettableContractResolver.cs.

    STJ doesn't have custom contract resolvers (dotnet/runtime#31257, dotnet/runtime#36785 ), nor any sort of equivalent of the "ShouldSerialize" pattern, as far as I can tell. I can't figure out a decent workaround, so I'm basically stuck here. Has anyone else done anything similar?

    the main workaround is to keep using Json.NET
    Magnus Grindal Bakken
    Yes, of course. :)
    ah, you might want this: dotnet/runtime#36322
    Hugh Gleaves
    Hi, I have a naive question and need some basic guidance
    concerned with providing hosted web tools which are only intended to be accessed from a consumer (e.g. GitHub) and not accessible by someone putting the tools URL into a browser

    Hello there,

    I have a web browser extension app that talks to ASP.NET core 3.1 web API. Every conversation between them must include a file (around 100kb or so). Currently, the file is a base64 string within HTTP post JSON requests. Upon receiving the file, the API converts it into a file on the server and updates and sends it back. This approach was the fastest way for me to implement it. The problem with this approach is now it appears slow under stress tests. Any suggestions on making them talk faster?