What is the best way to test if a url & querystring is valid? For example, after a login redirect I want to make sure the target url is valid. If not, go to a default page.
We seem to have a problem with the querystring, starting with “ReturnUrl=”, being duplicated and that throws an exception. We’d rather have it go to a default page.
Here is a workaround for too long
ReturnUrlquerystring parameter. The fact is if there was something in the querystring before appending newRedirectUrlparameter (e.g. by usingFormsAuthentication.RedirectToLoginPagemethod), this would be encoded and assigned to the newRedirectUrlparameter.The idea is to remove unnecessary(old
ReturnUrlparameters from the querystring). For this I useApplication_EndRequestinglobal.asaxandResponse.RedirectLocationproperty.So if the response is being redirected and current url contains
ReturnUrlparameter, it should be removed from redirected location (because it doesn’t make sense).For URL parsing and building
System.Uriwill be the best choice.