Home
%3CLINGO-SUB%20id%3D%22lingo-sub-898576%22%20slang%3D%22en-US%22%3EAzure%20Application%20Gateway%3A%20App%20Service%20Redirects%20exposing%20default%20URL%20on%20the%20Browser%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-898576%22%20slang%3D%22en-US%22%3E%3CP%3EYou%20may%20have%20faced%20some%20issues%20while%20securing%20App%20Services%20behind%20an%20Azure%20Application%20Gateway.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMore%20often%20than%20not%2C%20these%20issues%20are%20not%20really%20caused%20due%20to%20problems%20with%20the%20App%20Service%20or%20Application%20Gateway%20itself%2C%20but%20with%20the%20way%20the%20configuration%20%26amp%3B%20functioning%20of%20these%20products%2Fservices%20are%20interpreted.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20this%20blog%20post%2C%20I'm%20calling%20out%20one%20such%20scenario%20where%20redirects%20configured%20at%20the%20App%20Service%20web.config%2C%20end%20up%20exposing%20*.azurewebsites.net%20to%20the%20client%20(for%20example%2C%20on%20the%20browser's%20address%20bar)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ECONFIGURATION%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECustom%20Domain%20(%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E)%20has%20a%20C-Name%20to%20Application%20Gateway%E2%80%99s%20default%20domain%20(*.cloudapp.net).%3C%2FLI%3E%0A%3CLI%3EApplication%20Gateway%20has%20App%20Service%20Configured%20as%20the%20Backend%20Pool.%3C%2FLI%3E%0A%3CLI%3EProbes%20%26amp%3B%20listeners%20are%20in%20place%20for%20the%20App%20Service%20Backend%20Pool.%3C%2FLI%3E%0A%3CLI%3EBackend%20App%20Service%20has%20rewrite%20rules%20configured.%20(Say%2C%20HTTP%20to%20HTTPS)%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3ESYMPTOM%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWhen%20a%20request%20is%20made%20to%20the%20Application%20Gateway%E2%80%99s%20Custom%20Domain%20name%20(%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E)%20%E2%80%93%26gt%3B%20%26nbsp%3Bappname.azurewebsites.net%20is%20exposed%20on%20the%20browser.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EWHY%20IS%20THIS%20AN%20ISSUE%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EOne%20of%20the%20main%20intentions%20for%20customers%20to%20use%20Application%20Gateway%20in%20front%20of%20App%20Service%20is%20to%20avoid%20exposing%20the%20backend%20application%E2%80%99s%20whereabouts%20to%20the%20end%20user.%3C%2FLI%3E%0A%3CLI%3EHowever%2C%20the%20scenario%20addressed%20here%20defeats%20the%20purpose%20of%20the%20Application%20Gateway.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EHERE%E2%80%99S%20WHAT%E2%80%99S%20ACTUALLY%20HAPPENING%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EBrowser%20makes%20a%20request%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.customdomain.com%2F%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3ESince%20the%20DNS%20C-Name%20entry%20for%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Epoints%20to%20the%20Application%20Gateway%2C%20the%20request%20is%20sent%20to%20the%20Application%20Gateway.%3C%2FLI%3E%0A%3CLI%3EApplication%20Gateway%20receives%20this%20request%2C%20terminates%20the%20request%20%E2%80%93%20and%20fires%20a%20new%20request%20to%20the%20backend%20pool%E2%80%99s%20address.%3C%2FLI%3E%0A%3CLI%3ENow%2C%20if%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%E2%80%98Pick%20host%20name%20from%20backend%20address%E2%80%99%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20set%20to%20%E2%80%98%3CSTRONG%3ETrue%3C%2FSTRONG%3E%E2%80%99%20in%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EApp%20Gateway%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EBackendHttpSettings%3C%2FSTRONG%3E%2C%20the%20new%20request%20is%20actually%20fired%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fappname.azurewebsites.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fappname.azurewebsites.net%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ENOT%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E.%3C%2FLI%3E%0A%3CLI%3EBackend%20App%20Service%20receives%20this%20request%20and%20the%20re-write%20rules%20are%20processed.%20Let%E2%80%99s%20say%20this%20App%20Service%20has%20an%20HTTP%20to%20HTTPS%20URL%20rewrite%20rule%20configured.%3C%2FLI%3E%0A%3CLI%3EDue%20to%20the%20HTTP%20to%20HTTPS%20redirect%2C%20App%20Service%20returns%20a%20response%20with%20status%20code%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EHTTP%20302%2F301%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eand%20a%20location%20tag%20with%20this%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fappname.azurewebsites.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fappname.azurewebsites.net%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20its%20value.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20484px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135784i2DF4AD58D63CB111%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EThe%20Application%20Gateway%20receives%20this%20response%2C%20and%20returns%20the%20same%20HTTP%20302%2F301%20response%20back%20to%20the%20browser.%3C%2FLI%3E%0A%3CLI%3EThe%20browser%20then%20fires%20a%20new%20request%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fappname.azurewebsites.net%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fappname.azurewebsites.net%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ewhich%20is%20the%20value%20in%20the%20location%20tag.%3C%2FLI%3E%0A%3CLI%3EThis%20is%20how%20the%20*.azurewebsites.net%20is%20exposed%20on%20the%20browser%20URL.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3EA%20little%20about%20%E2%80%98PickHostNameFromBackendHttpSettings%E2%80%99%20%E2%80%93%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWhat%20does%20this%20setting%20do%3F%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%3EWhen%20this%20flag%20is%20checked%2C%20it%20means%20that%20the%20host%20header%20should%20be%20picked%20from%20the%20backend%20http%20settings.%3C%2FLI%3E%0A%3CLI%3EThis%20means%20that%20the%20Application%20Gateway%20will%20fire%20a%20request%20to%20the%20App%20Service%20with%20appname.azurewebsites.net%20as%20the%20hostname.%3C%2FLI%3E%0A%3CLI%3EThis%20also%20means%20that%20the%20AppGW%20will%20not%20retain%20the%20Custom%20Domain%20name%20while%20making%20a%20call%20to%20the%20backend.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20914px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135785i063321A64273F4B8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EHOW%20DO%20WE%20FIX%20THIS%3F%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EHere%E2%80%99s%20a%20solution%20we%20can%20suggest%20our%20customers%20when%20the%20redirects%20at%20the%20backends%20cause%20such%20issues%3A%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESolution%20%E2%80%93%20Ensure%20that%20any%20redirects%20respect%20the%20domain%20that%20the%20user%20has%20originally%20requested%20(i.e.%20the%20application%20gateway%20domain).%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EMap%20the%20domain%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Eto%20the%20backend%20App%20Service%20as%20a%20custom%20domain%20name.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%3ETo%20do%20this%20create%20records%20in%20your%20DNS%20registrar%20with%20the%20following%20value%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CTABLE%20class%3D%22wp-block-table%20alignfull%22%3E%0A%3CTHEAD%3E%0A%3CTR%3E%0A%3CTD%3E%3CSTRONG%3ERecord%20Type%3C%2FSTRONG%3E%3C%2FTD%3E%0A%3CTD%3E%3CSTRONG%3EHost%20Name%3C%2FSTRONG%3E%3C%2FTD%3E%0A%3CTD%3E%3CSTRONG%3EValue%3C%2FSTRONG%3E%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTHEAD%3E%0A%3CTBODY%3E%0A%3CTR%3E%0A%3CTD%3ETXT%3C%2FTD%3E%0A%3CTD%3Eawverify.%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E%3C%2FTD%3E%0A%3CTD%3Eappname.azurewebsites.net%3C%2FTD%3E%0A%3C%2FTR%3E%0A%3C%2FTBODY%3E%0A%3C%2FTABLE%3E%0A%3CUL%3E%0A%3CLI%3EThe%20above%20record%20helps%20in%20validation%20at%20the%20App%20Service%20level.%20Once%20this%20record%20is%20in%20place%2C%20add%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eas%20a%20custom%20domain%20name%20to%20the%20App%20Service.%3C%2FLI%3E%0A%3CLI%3EThe%20TXT%20record%20can%20be%20removed%20after%20App%20Service%20validation.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%3EEnsure%20that%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ewww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Estill%20has%20the%20C-Name%20to%20Application%20Gateway%20(*.cloudapp.net).%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%3EEnsure%20that%20the%20Application%20Gateway%20sends%20request%20to%20the%20backend%20App%20Service%20without%20modifying%20the%20hostname%20to%20appname.azurewebsites.net%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CUL%3E%0A%3CLI%3ETo%20do%20this%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3Euncheck%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Ethe%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EUse%20for%20App%20Service%3C%2FSTRONG%3E%2C%20and%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EPick%20Hostname%20from%20Backend%20Address%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eso%20that%20the%20hostname%20in%20the%20packet%20is%20not%20altered.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20890px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F135786iC48C508217857DEE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22image.png%22%20title%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EWhen%20this%20happens%2C%20the%20App%20Gateway%20receives%20a%20request%20for%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%2C%20forwards%20the%20same%20to%20the%20backend%2C%20backend%20receives%20request%20over%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22http%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fwww.customdomain.com%3C%2FA%3E%2C%20processes%20the%20redirect%20request%2C%20replies%20with%20a%20location%20tag%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%2C%20AppGW%20forwards%20the%20same%20response%20to%20the%20browser%20and%20the%20browser%20fires%20another%20request%20to%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CA%20href%3D%22https%3A%2F%2Fwww.customdomain.com%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.customdomain.com%3C%2FA%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E.%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EThis%20way%2C%20the%20domain%20name%20is%20honoured%20throughout%20the%20cycle%2C%20thus%20avoiding%20the%20exposure%20of%20azurewebsites.net%20URL%20to%20the%20end%20user.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3EI%20hope%20this%20helps!%3CSPAN%3E%26nbsp%3B%3A)%3C%2Fimg%3E%3C%2FSPAN%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-898576%22%20slang%3D%22en-US%22%3E%3CP%3EHow%20do%20you%20avoid%20exposing%20your%20web%20app's%20default%20URL%20on%20the%20browser%20when%20Application%20Gateway%20is%20configured%3F%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-SUB%20id%3D%22lingo-sub-899270%22%20slang%3D%22en-US%22%3ERe%3A%20Azure%20Application%20Gateway%3A%20App%20Service%20Redirects%20exposing%20default%20URL%20on%20the%20Browser%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-899270%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F360851%22%20target%3D%22_blank%22%3E%40madhurabharadwaj%3C%2FA%3E%26nbsp%3Bvery%20informative%20article%2C%20thank%20you%20for%20sharing.%3C%2FP%3E%3C%2FLINGO-BODY%3E

You may have faced some issues while securing App Services behind an Azure Application Gateway.

 

More often than not, these issues are not really caused due to problems with the App Service or Application Gateway itself, but with the way the configuration & functioning of these products/services are interpreted.

 

In this blog post, I'm calling out one such scenario where redirects configured at the App Service web.config, end up exposing *.azurewebsites.net to the client (for example, on the browser's address bar)

 

CONFIGURATION:

  • Custom Domain (www.customdomain.com) has a C-Name to Application Gateway’s default domain (*.cloudapp.net).
  • Application Gateway has App Service Configured as the Backend Pool.
  • Probes & listeners are in place for the App Service Backend Pool.
  • Backend App Service has rewrite rules configured. (Say, HTTP to HTTPS)

SYMPTOM:

  • When a request is made to the Application Gateway’s Custom Domain name (www.customdomain.com) –>  appname.azurewebsites.net is exposed on the browser.

WHY IS THIS AN ISSUE?

  • One of the main intentions for customers to use Application Gateway in front of App Service is to avoid exposing the backend application’s whereabouts to the end user.
  • However, the scenario addressed here defeats the purpose of the Application Gateway.

HERE’S WHAT’S ACTUALLY HAPPENING:

  1. Browser makes a request to http://www.customdomain.com/
  2. Since the DNS C-Name entry for www.customdomain.com points to the Application Gateway, the request is sent to the Application Gateway.
  3. Application Gateway receives this request, terminates the request – and fires a new request to the backend pool’s address.
  4. Now, if ‘Pick host name from backend address’ is set to ‘True’ in the App Gateway BackendHttpSettings, the new request is actually fired to http://appname.azurewebsites.net and NOT to http://www.customdomain.com .
  5. Backend App Service receives this request and the re-write rules are processed. Let’s say this App Service has an HTTP to HTTPS URL rewrite rule configured.
  6. Due to the HTTP to HTTPS redirect, App Service returns a response with status code HTTP 302/301 and a location tag with this https://appname.azurewebsites.net as its value.

image.png

 

  • The Application Gateway receives this response, and returns the same HTTP 302/301 response back to the browser.
  • The browser then fires a new request to https://appname.azurewebsites.net which is the value in the location tag.
  • This is how the *.azurewebsites.net is exposed on the browser URL.

A little about ‘PickHostNameFromBackendHttpSettings’ –

  • What does this setting do?
  • When this flag is checked, it means that the host header should be picked from the backend http settings.
  • This means that the Application Gateway will fire a request to the App Service with appname.azurewebsites.net as the hostname.
  • This also means that the AppGW will not retain the Custom Domain name while making a call to the backend.

image.png

HOW DO WE FIX THIS?

Here’s a solution we can suggest our customers when the redirects at the backends cause such issues:

Solution – Ensure that any redirects respect the domain that the user has originally requested (i.e. the application gateway domain).

  • To do this create records in your DNS registrar with the following value
Record Type Host Name Value
TXT awverify.www.customdomain.com appname.azurewebsites.net
  • The above record helps in validation at the App Service level. Once this record is in place, add www.customdomain.com as a custom domain name to the App Service.
  • The TXT record can be removed after App Service validation.
  • Ensure that the Application Gateway sends request to the backend App Service without modifying the hostname to appname.azurewebsites.net
  • To do this, uncheck the Use for App Service, and Pick Hostname from Backend Address so that the hostname in the packet is not altered.

image.png

I hope this helps! :) 

1 Comment
Occasional Contributor

@madhurabharadwaj very informative article, thank you for sharing.