locked
How to convert the following into .NET Core. RRS feed

  • Question

  • User2056817590 posted
    1. var response = Request["g-recaptcha-response"];
    2.  string activationProtocol = Request.Url.Scheme;
    3. model.ActivationUrl = Url.Action(String.Empty, "Activate", routeValues: null, protocol: activationProtocol);
    4. foreach (String key in Session.Keys)
                  {
                      _logger.Debug(String.Format("Session Key={0}, Value={1} ", key, Session[key]));
                  }
    Friday, April 9, 2021 10:43 AM

All replies

  • User475983607 posted

    As recommended in many of your recent posts, learn .NET Core fundamentals.   Any beginning level tutorial will have this information or reading the .NET Core fundamentals documentation.

    https://docs.microsoft.com/en-us/aspnet/core/fundamentals/?view=aspnetcore-5.0&tabs=windows

    kalvakrishna

    var response = Request["g-recaptcha-response"];

    Request["g-recaptcha-response"] has been replaced by model binding but the syntax still works.  

    https://docs.microsoft.com/en-us/aspnet/core/mvc/models/model-binding?view=aspnetcore-5.0

    HttpContext.Request.Form["key"]

    kalvakrishna

     string activationProtocol = Request.Url.Scheme;

    HttpContext.Request.Scheme

    kalvakrishna

    model.ActivationUrl = Url.Action(String.Empty, "Activate", routeValues: null, protocol: activationProtocol);

    Works the same in .NET 5 (Core).

    kalvakrishna

    foreach (String key in Session.Keys)
                {
                    _logger.Debug(String.Format("Session Key={0}, Value={1} ", key, Session[key]));
                }

    Accessing Session is cover extensively in your recent post(s). 

    https://forums.asp.net/t/2175507.aspx

    Friday, April 9, 2021 11:09 AM
  • User2056817590 posted
    • getting error "Cannot apply indexing with [] to an expression of type 'HttpRequest'" for   

    var response = Request["g-recaptcha-response"];

    • No overload for method 'Action' takes 4 arguments    

    string activationUrl = Url.Action(String.Empty, "ForgotPasswordActivate", routeValues: null, protocol: activationProtocol);

    • string activationProtocol = Request.Url.Scheme;

      Please let me know the converted code in .NET Core 

    Friday, April 9, 2021 11:35 AM
  • User475983607 posted

    kalvakrishna

    • getting error "Cannot apply indexing with [] to an expression of type 'HttpRequest'" for   

    var response = Request["g-recaptcha-response"];

    You did not follow the instructions or read the doc???

    HttpContext.Request.Form["key"]

    kalvakrishna

    • No overload for method 'Action' takes 4 arguments    

    string activationUrl = Url.Action(String.Empty, "ForgotPasswordActivate", routeValues: null, protocol: activationProtocol);

    The overload is... 

    string activationUrl = Url.Action(String.Empty, "ForgotPasswordActivate", null, activationProtocol);

    https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.urlhelper.action?view=aspnet-mvc-5.2#System_Web_Mvc_UrlHelper_Action_System_String_System_String_System_Object_System_String_

    Friday, April 9, 2021 11:45 AM