Creating Cookies Serverside WebAPi 2












0















I'm really struggling to create a cookie server side. At the moment we have not decided on which toolset will be used for the front end code (Razor, Angular, React etc), but we do know we are using MVC Web APi .net core 2.1 on the backend.



For now we have a basic Login page that calls a method. As part of that call I create a string based token, and because we are using Jquery Ajax to make the call, I'm currently passing it back to the client. However, the client doesn't really need to be concerned about the token, only the API needs to know about it. So when I make the call to my initial server Method and create my token I want to store it in a Cookie, but this is proving difficult. All the examples I've found seem to return an HttpResponseMessage back to the client.



I've tried simple things like Response.Headers.Add("mycookie",value); to creating a HttpResponseMessage with a CookieHeaderValue but nothing is set.



I don't receive any errors with anything I'm doing, but after returning from my initial page in my ajax call and redirecting to another method on the api, If I try and read the request objects cookies, there are none. I don't really want to create the cookie client side.










share|improve this question



























    0















    I'm really struggling to create a cookie server side. At the moment we have not decided on which toolset will be used for the front end code (Razor, Angular, React etc), but we do know we are using MVC Web APi .net core 2.1 on the backend.



    For now we have a basic Login page that calls a method. As part of that call I create a string based token, and because we are using Jquery Ajax to make the call, I'm currently passing it back to the client. However, the client doesn't really need to be concerned about the token, only the API needs to know about it. So when I make the call to my initial server Method and create my token I want to store it in a Cookie, but this is proving difficult. All the examples I've found seem to return an HttpResponseMessage back to the client.



    I've tried simple things like Response.Headers.Add("mycookie",value); to creating a HttpResponseMessage with a CookieHeaderValue but nothing is set.



    I don't receive any errors with anything I'm doing, but after returning from my initial page in my ajax call and redirecting to another method on the api, If I try and read the request objects cookies, there are none. I don't really want to create the cookie client side.










    share|improve this question

























      0












      0








      0








      I'm really struggling to create a cookie server side. At the moment we have not decided on which toolset will be used for the front end code (Razor, Angular, React etc), but we do know we are using MVC Web APi .net core 2.1 on the backend.



      For now we have a basic Login page that calls a method. As part of that call I create a string based token, and because we are using Jquery Ajax to make the call, I'm currently passing it back to the client. However, the client doesn't really need to be concerned about the token, only the API needs to know about it. So when I make the call to my initial server Method and create my token I want to store it in a Cookie, but this is proving difficult. All the examples I've found seem to return an HttpResponseMessage back to the client.



      I've tried simple things like Response.Headers.Add("mycookie",value); to creating a HttpResponseMessage with a CookieHeaderValue but nothing is set.



      I don't receive any errors with anything I'm doing, but after returning from my initial page in my ajax call and redirecting to another method on the api, If I try and read the request objects cookies, there are none. I don't really want to create the cookie client side.










      share|improve this question














      I'm really struggling to create a cookie server side. At the moment we have not decided on which toolset will be used for the front end code (Razor, Angular, React etc), but we do know we are using MVC Web APi .net core 2.1 on the backend.



      For now we have a basic Login page that calls a method. As part of that call I create a string based token, and because we are using Jquery Ajax to make the call, I'm currently passing it back to the client. However, the client doesn't really need to be concerned about the token, only the API needs to know about it. So when I make the call to my initial server Method and create my token I want to store it in a Cookie, but this is proving difficult. All the examples I've found seem to return an HttpResponseMessage back to the client.



      I've tried simple things like Response.Headers.Add("mycookie",value); to creating a HttpResponseMessage with a CookieHeaderValue but nothing is set.



      I don't receive any errors with anything I'm doing, but after returning from my initial page in my ajax call and redirecting to another method on the api, If I try and read the request objects cookies, there are none. I don't really want to create the cookie client side.







      asp.net-mvc asp.net-web-api cookies






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 14 '18 at 12:46









      bilporbilpor

      1,08511228




      1,08511228
























          0






          active

          oldest

          votes











          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%2f53300579%2fcreating-cookies-serverside-webapi-2%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f53300579%2fcreating-cookies-serverside-webapi-2%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

          Bressuire

          Vorschmack

          Quarantine