Are ProfileBase, HttpContext.Request.AnonymousId available as a part of the ASP.Net Core 2.x suite? If so how...











up vote
0
down vote

favorite












I am currently trying to migrate ASP.Net MVC API 4.6.2 app to ASP.Net Core 2.1.



     private static string GetSessionId()
{
// Get from the session state, most reliable, but not likely available
if (HttpContext.Current.Session != null && !string.IsNullOrEmpty(HttpContext.Current.Session.SessionID))
{
return HttpContext.Current.Session.SessionID;
}

// if the application has enabled anonymous tracking, then this is also reliable
// (note: this requires <anonymousIdentification enabled="true" /> in the web.onfig.
if (HttpContext.Current.Profile.IsAnonymous &&
!string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))
{
return HttpContext.Current.Request.AnonymousID;
}

// last resort, we track this ourselves.
var telemetryId = HttpContext.Current.Request.Cookies[TelemetryKey] != null
? HttpContext.Current.Request.Cookies[TelemetryKey].Value
: Guid.NewGuid().ToString();
var telemetryCookie = new HttpCookie(TelemetryKey, telemetryId) { Expires = DateTime.Now.AddYears(1) };
HttpContext.Current.Response.SetCookie(telemetryCookie);

return telemetryId;
}


Now in the .Net Core version, I am unable to find equivalents. And yes, I have registered the IHttpContextAccessor through ConfigureServices() and am able to access it in this service class. But, the current HttpContext does not seem to have all the properties that the Sytem.Web.Http namespace offered.



Are there any alternatives to check if the user is anoanymous?



    (HttpContext.Current.Profile.IsAnonymous && 
string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))


Also, it'd be great if any suggestions could be made about retaining Http calls in a .Net standard class library.



Thanks in advance.










share|improve this question


























    up vote
    0
    down vote

    favorite












    I am currently trying to migrate ASP.Net MVC API 4.6.2 app to ASP.Net Core 2.1.



         private static string GetSessionId()
    {
    // Get from the session state, most reliable, but not likely available
    if (HttpContext.Current.Session != null && !string.IsNullOrEmpty(HttpContext.Current.Session.SessionID))
    {
    return HttpContext.Current.Session.SessionID;
    }

    // if the application has enabled anonymous tracking, then this is also reliable
    // (note: this requires <anonymousIdentification enabled="true" /> in the web.onfig.
    if (HttpContext.Current.Profile.IsAnonymous &&
    !string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))
    {
    return HttpContext.Current.Request.AnonymousID;
    }

    // last resort, we track this ourselves.
    var telemetryId = HttpContext.Current.Request.Cookies[TelemetryKey] != null
    ? HttpContext.Current.Request.Cookies[TelemetryKey].Value
    : Guid.NewGuid().ToString();
    var telemetryCookie = new HttpCookie(TelemetryKey, telemetryId) { Expires = DateTime.Now.AddYears(1) };
    HttpContext.Current.Response.SetCookie(telemetryCookie);

    return telemetryId;
    }


    Now in the .Net Core version, I am unable to find equivalents. And yes, I have registered the IHttpContextAccessor through ConfigureServices() and am able to access it in this service class. But, the current HttpContext does not seem to have all the properties that the Sytem.Web.Http namespace offered.



    Are there any alternatives to check if the user is anoanymous?



        (HttpContext.Current.Profile.IsAnonymous && 
    string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))


    Also, it'd be great if any suggestions could be made about retaining Http calls in a .Net standard class library.



    Thanks in advance.










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I am currently trying to migrate ASP.Net MVC API 4.6.2 app to ASP.Net Core 2.1.



           private static string GetSessionId()
      {
      // Get from the session state, most reliable, but not likely available
      if (HttpContext.Current.Session != null && !string.IsNullOrEmpty(HttpContext.Current.Session.SessionID))
      {
      return HttpContext.Current.Session.SessionID;
      }

      // if the application has enabled anonymous tracking, then this is also reliable
      // (note: this requires <anonymousIdentification enabled="true" /> in the web.onfig.
      if (HttpContext.Current.Profile.IsAnonymous &&
      !string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))
      {
      return HttpContext.Current.Request.AnonymousID;
      }

      // last resort, we track this ourselves.
      var telemetryId = HttpContext.Current.Request.Cookies[TelemetryKey] != null
      ? HttpContext.Current.Request.Cookies[TelemetryKey].Value
      : Guid.NewGuid().ToString();
      var telemetryCookie = new HttpCookie(TelemetryKey, telemetryId) { Expires = DateTime.Now.AddYears(1) };
      HttpContext.Current.Response.SetCookie(telemetryCookie);

      return telemetryId;
      }


      Now in the .Net Core version, I am unable to find equivalents. And yes, I have registered the IHttpContextAccessor through ConfigureServices() and am able to access it in this service class. But, the current HttpContext does not seem to have all the properties that the Sytem.Web.Http namespace offered.



      Are there any alternatives to check if the user is anoanymous?



          (HttpContext.Current.Profile.IsAnonymous && 
      string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))


      Also, it'd be great if any suggestions could be made about retaining Http calls in a .Net standard class library.



      Thanks in advance.










      share|improve this question













      I am currently trying to migrate ASP.Net MVC API 4.6.2 app to ASP.Net Core 2.1.



           private static string GetSessionId()
      {
      // Get from the session state, most reliable, but not likely available
      if (HttpContext.Current.Session != null && !string.IsNullOrEmpty(HttpContext.Current.Session.SessionID))
      {
      return HttpContext.Current.Session.SessionID;
      }

      // if the application has enabled anonymous tracking, then this is also reliable
      // (note: this requires <anonymousIdentification enabled="true" /> in the web.onfig.
      if (HttpContext.Current.Profile.IsAnonymous &&
      !string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))
      {
      return HttpContext.Current.Request.AnonymousID;
      }

      // last resort, we track this ourselves.
      var telemetryId = HttpContext.Current.Request.Cookies[TelemetryKey] != null
      ? HttpContext.Current.Request.Cookies[TelemetryKey].Value
      : Guid.NewGuid().ToString();
      var telemetryCookie = new HttpCookie(TelemetryKey, telemetryId) { Expires = DateTime.Now.AddYears(1) };
      HttpContext.Current.Response.SetCookie(telemetryCookie);

      return telemetryId;
      }


      Now in the .Net Core version, I am unable to find equivalents. And yes, I have registered the IHttpContextAccessor through ConfigureServices() and am able to access it in this service class. But, the current HttpContext does not seem to have all the properties that the Sytem.Web.Http namespace offered.



      Are there any alternatives to check if the user is anoanymous?



          (HttpContext.Current.Profile.IsAnonymous && 
      string.IsNullOrEmpty(HttpContext.Current.Request.AnonymousID))


      Also, it'd be great if any suggestions could be made about retaining Http calls in a .Net standard class library.



      Thanks in advance.







      .net asp.net-core migration httpcontext asp.net-core-2.1






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 23:08









      Abhay Nagaraj

      63




      63
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          Found out that the AnonymousId has been discontinued in .Net Core due to its negligible usage and needs to implemented through a custom middle-ware if necessary.
          While writing the custom middle-ware for achieving the same I discovered that somebody had already walked this path before and had written a custom middle-ware which can be found at the following link: https://github.com/aleripe/AnonymousId



          It saved a lot of my time and hope it does yours too if you were looking for something of this sort.



          FYI: I couldn't find much about the ProfileBase library in .Net Core.






          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',
            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%2f53234409%2fare-profilebase-httpcontext-request-anonymousid-available-as-a-part-of-the-asp%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








            up vote
            0
            down vote













            Found out that the AnonymousId has been discontinued in .Net Core due to its negligible usage and needs to implemented through a custom middle-ware if necessary.
            While writing the custom middle-ware for achieving the same I discovered that somebody had already walked this path before and had written a custom middle-ware which can be found at the following link: https://github.com/aleripe/AnonymousId



            It saved a lot of my time and hope it does yours too if you were looking for something of this sort.



            FYI: I couldn't find much about the ProfileBase library in .Net Core.






            share|improve this answer

























              up vote
              0
              down vote













              Found out that the AnonymousId has been discontinued in .Net Core due to its negligible usage and needs to implemented through a custom middle-ware if necessary.
              While writing the custom middle-ware for achieving the same I discovered that somebody had already walked this path before and had written a custom middle-ware which can be found at the following link: https://github.com/aleripe/AnonymousId



              It saved a lot of my time and hope it does yours too if you were looking for something of this sort.



              FYI: I couldn't find much about the ProfileBase library in .Net Core.






              share|improve this answer























                up vote
                0
                down vote










                up vote
                0
                down vote









                Found out that the AnonymousId has been discontinued in .Net Core due to its negligible usage and needs to implemented through a custom middle-ware if necessary.
                While writing the custom middle-ware for achieving the same I discovered that somebody had already walked this path before and had written a custom middle-ware which can be found at the following link: https://github.com/aleripe/AnonymousId



                It saved a lot of my time and hope it does yours too if you were looking for something of this sort.



                FYI: I couldn't find much about the ProfileBase library in .Net Core.






                share|improve this answer












                Found out that the AnonymousId has been discontinued in .Net Core due to its negligible usage and needs to implemented through a custom middle-ware if necessary.
                While writing the custom middle-ware for achieving the same I discovered that somebody had already walked this path before and had written a custom middle-ware which can be found at the following link: https://github.com/aleripe/AnonymousId



                It saved a lot of my time and hope it does yours too if you were looking for something of this sort.



                FYI: I couldn't find much about the ProfileBase library in .Net Core.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 12 at 20:22









                Abhay Nagaraj

                63




                63






























                    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.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • 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%2f53234409%2fare-profilebase-httpcontext-request-anonymousid-available-as-a-part-of-the-asp%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







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini