I’ve used OWIN to develop Single Sign On for Microsoft Azure and it worked (port 443) but now the customer have installed an Application Gateway (https) and my application have to run on port 80 (http).
This scenario cause me various problem and now I must adapt the code to run with this solution.
In order to to this, I try to read the X-Forwarded-Proto header,but I got this error:
The application runs on .NET FW 4.8
Private Const ForwardedHeadersAdded As String = "ForwardedHeadersAdded"
Public Shared Function UseForwardedHeaders(ByVal app As IAppBuilder) As IAppBuilder
If app Is Nothing Then
Throw New ArgumentNullException(NameOf(app))
End If
If Not app.Properties.ContainsKey(ForwardedHeadersAdded) Then
app.Properties(ForwardedHeadersAdded) = True
app.Use(Async Function(context, [next])
Dim request = context.Request
If request.Scheme <> Uri.UriSchemeHttps AndAlso String.Equals(request.Headers("X-Forwarded-Proto"), Uri.UriSchemeHttps, StringComparison.OrdinalIgnoreCase) Then
Dim httpContext = context.[Get](Of HttpContextBase)(GetType(HttpContextBase).FullName)
Dim serverVars = httpContext.Request.ServerVariables
serverVars("HTTPS") = "on"
serverVars("SERVER_PORT_SECURE") = "1"
serverVars("SERVER_PORT") = "443"
serverVars("HTTP_HOST") = If(request.Headers.ContainsKey("X-Forwarded-Host"), request.Headers("X-Forwarded-Host"), serverVars("HTTP_HOST"))
End If
Await [next].Invoke().ConfigureAwait(False)
End Function)
End If
Return app
End Function
and when using
UseForwardedHeaders(app)
Thank you in advance
I tryed to not change the code but the code didn’t work.
Some errors were appeared like RequireNonce is System.Boolean, RequireStatus is System.Boolean etc…