Recently I encountered a backflow problem when using CAS for SSO.
(Brief description of reflux:
The application and service are in the same Intranet IP address, and the service and application are mapped to the Internet IP address. When the application uses the Internet IP address to access the service, the access is denied. Because the ingress detects that the accessed service is on the same Intranet IP address, it can only be accessed through the Intranet IP address, or the routing configuration is changed .)
Here we will introduce the software solution:
Because you cannot directly change the IP Address Configuration to the Intranet IP address for CAS verification, you can only dynamically determine that the address in the URL is automatically replaced with the local address when a webexception occurs, to solve the backflow problem.
The judgment code is as follows (replacelocalip is used to replace the local address)
try { serverResponse = RetrieveResponseFromServer(validationUrl, ticket); } catch (WebException) { validationUrl = ReplaceLocalIP(validationUrl); serverResponse = RetrieveResponseFromServer(validationUrl, ticket); }
Replacelocalip method:
/// <Summary> /// replace it with the local address to address the backflow problem // </Summary> /// <Param name = "validationurl"> </param> // /<returns> </returns> private string replacelocalip (string validationurl) {int iindex = validationurl. indexof ("//"); int iindex1 = validationurl. indexof ("/", iindex + 2); string shostold = validationurl. substring (iindex + 2, iindex1-iindex + 2); string [] arrayadd = shostold. split (':'); arrayadd [0] = "127.0.0.1"; string shostnew = string. empty; foreach (VAR item in arrayadd) shostnew + = item + ":"; shostnew = shostnew. remove (shostnew. length-1); string sresult = validationurl. replace (shostold, shostnew); Return sresult ;}