Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
TL;DR: Properties that need to be converted from HttpRequestBase to HttpRequest at the bottom along with my best guesses

I'm developing a web application that uses ASP.Net 3.1 Core and I am trying to implement OAuth 2 authentication.

The sample code that I am following is old (uses System.Web) and I'm having issues trying to convert this to the newer standards.

The original code in the Controller class has:
C#
[HttpPost]
public async Task<ActionResult> oauth2Request()
{
	oauthHelper oauth = new oauthHelper(Request);

Where Request is of type System.Web.Mvc.HttpRequestBase.

When I do the equivalent code in my application, I have:
C#
[HttpPost]
public async Task<IActionResult> oauth2Request()
{
	oauthHelper oauth = new oauthHelper(Request);

and Request is now Microsoft.AspNetCore.Http.HttpRequest.

I need to get the equivelent properties out of Microsoft.AspNetCore.Http.HttpRequest:
System.Web.Mvc.HttpRequestBase.Form (NameValueCollection)
[Microsoft.AspNetCore.Http.HttpRequest.HttpContext.Request.Form with a loop to change the KeyValuePairs to the NameValueCollection ?]

System.Web.Mvc.HttpRequestBase.UserHostAddress (string)
[Microsoft.AspNetCore.Http.HttpRequest.HttpContext.Connection.RemoteIpAddress.ToString() ?]

System.Web.Mvc.HttpRequestBase.Url (Uri)

System.Web.Mvc.HttpRequestBase.HttpMethod (string)
[Microsoft.AspNetCore.Http.HttpRequest.Method ?]

What I have tried:

I've shown three of the four properties that I need with my best guess. If these are wrong, please let me know.

I have no idea at all how to do the conversion from the
HttpRequestBase.Url
property. I don't even know what it is supposed to contain.
Posted
Updated 7-Jul-20 7:21am

1 solution

Don't try to adapt code written for ASP.NET to use in ASP.NET Core. It's not likely to work.

There are lots of examples of setting up OAuth2 in ASP.NET Core which won't require you to jump through these hoops. For example:
Facebook, Google, and external provider authentication in ASP.NET Core | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900