prepend a string in all responses within ASP.NET core json





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















I would like to prepend all JSON responses with following string:



)]}',n


What is the best way to achieve this with ASP.NET Core? I would like to have it enabled for all JSON responses automatically.










share|improve this question

























  • stackoverflow.com/a/49189185/11683

    – GSerg
    Nov 16 '18 at 12:30











  • Just curious: why ? SHouldn't the proper json syntax be produced by a library (typically json.net) ? Why manipulating json string ?

    – Steve B
    Nov 16 '18 at 13:13






  • 1





    angular.io/guide/security#xssi

    – stephan.peters
    Nov 16 '18 at 13:17











  • So you want to prevent json hijacking. It may already not be relevant. The idiomatic ASP.NET MVC way to protect from it was JsonRequestBehavior.DenyGet, which was removed from MVC Core, apparently because it is not relevant anymore.

    – GSerg
    Nov 16 '18 at 21:55


















0















I would like to prepend all JSON responses with following string:



)]}',n


What is the best way to achieve this with ASP.NET Core? I would like to have it enabled for all JSON responses automatically.










share|improve this question

























  • stackoverflow.com/a/49189185/11683

    – GSerg
    Nov 16 '18 at 12:30











  • Just curious: why ? SHouldn't the proper json syntax be produced by a library (typically json.net) ? Why manipulating json string ?

    – Steve B
    Nov 16 '18 at 13:13






  • 1





    angular.io/guide/security#xssi

    – stephan.peters
    Nov 16 '18 at 13:17











  • So you want to prevent json hijacking. It may already not be relevant. The idiomatic ASP.NET MVC way to protect from it was JsonRequestBehavior.DenyGet, which was removed from MVC Core, apparently because it is not relevant anymore.

    – GSerg
    Nov 16 '18 at 21:55














0












0








0








I would like to prepend all JSON responses with following string:



)]}',n


What is the best way to achieve this with ASP.NET Core? I would like to have it enabled for all JSON responses automatically.










share|improve this question
















I would like to prepend all JSON responses with following string:



)]}',n


What is the best way to achieve this with ASP.NET Core? I would like to have it enabled for all JSON responses automatically.







json asp.net-core






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 12:23









GSerg

60.2k15107236




60.2k15107236










asked Nov 16 '18 at 12:21









stephan.petersstephan.peters

375318




375318













  • stackoverflow.com/a/49189185/11683

    – GSerg
    Nov 16 '18 at 12:30











  • Just curious: why ? SHouldn't the proper json syntax be produced by a library (typically json.net) ? Why manipulating json string ?

    – Steve B
    Nov 16 '18 at 13:13






  • 1





    angular.io/guide/security#xssi

    – stephan.peters
    Nov 16 '18 at 13:17











  • So you want to prevent json hijacking. It may already not be relevant. The idiomatic ASP.NET MVC way to protect from it was JsonRequestBehavior.DenyGet, which was removed from MVC Core, apparently because it is not relevant anymore.

    – GSerg
    Nov 16 '18 at 21:55



















  • stackoverflow.com/a/49189185/11683

    – GSerg
    Nov 16 '18 at 12:30











  • Just curious: why ? SHouldn't the proper json syntax be produced by a library (typically json.net) ? Why manipulating json string ?

    – Steve B
    Nov 16 '18 at 13:13






  • 1





    angular.io/guide/security#xssi

    – stephan.peters
    Nov 16 '18 at 13:17











  • So you want to prevent json hijacking. It may already not be relevant. The idiomatic ASP.NET MVC way to protect from it was JsonRequestBehavior.DenyGet, which was removed from MVC Core, apparently because it is not relevant anymore.

    – GSerg
    Nov 16 '18 at 21:55

















stackoverflow.com/a/49189185/11683

– GSerg
Nov 16 '18 at 12:30





stackoverflow.com/a/49189185/11683

– GSerg
Nov 16 '18 at 12:30













Just curious: why ? SHouldn't the proper json syntax be produced by a library (typically json.net) ? Why manipulating json string ?

– Steve B
Nov 16 '18 at 13:13





Just curious: why ? SHouldn't the proper json syntax be produced by a library (typically json.net) ? Why manipulating json string ?

– Steve B
Nov 16 '18 at 13:13




1




1





angular.io/guide/security#xssi

– stephan.peters
Nov 16 '18 at 13:17





angular.io/guide/security#xssi

– stephan.peters
Nov 16 '18 at 13:17













So you want to prevent json hijacking. It may already not be relevant. The idiomatic ASP.NET MVC way to protect from it was JsonRequestBehavior.DenyGet, which was removed from MVC Core, apparently because it is not relevant anymore.

– GSerg
Nov 16 '18 at 21:55





So you want to prevent json hijacking. It may already not be relevant. The idiomatic ASP.NET MVC way to protect from it was JsonRequestBehavior.DenyGet, which was removed from MVC Core, apparently because it is not relevant anymore.

– GSerg
Nov 16 '18 at 21:55












1 Answer
1






active

oldest

votes


















0














You could use a Middleware that checks the following condition (or whatever condition you need).



if(context.Response.ContentType == "application/json")



Then you just append prepend the context.Response.Body with your string.






share|improve this answer


























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337826%2fprepend-a-string-in-all-responses-within-asp-net-core-json%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You could use a Middleware that checks the following condition (or whatever condition you need).



    if(context.Response.ContentType == "application/json")



    Then you just append prepend the context.Response.Body with your string.






    share|improve this answer






























      0














      You could use a Middleware that checks the following condition (or whatever condition you need).



      if(context.Response.ContentType == "application/json")



      Then you just append prepend the context.Response.Body with your string.






      share|improve this answer




























        0












        0








        0







        You could use a Middleware that checks the following condition (or whatever condition you need).



        if(context.Response.ContentType == "application/json")



        Then you just append prepend the context.Response.Body with your string.






        share|improve this answer















        You could use a Middleware that checks the following condition (or whatever condition you need).



        if(context.Response.ContentType == "application/json")



        Then you just append prepend the context.Response.Body with your string.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 13:34

























        answered Nov 16 '18 at 12:57









        SenneSenne

        847




        847
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337826%2fprepend-a-string-in-all-responses-within-asp-net-core-json%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python