asp.net - VB.NET redirection loop error -
i have following code on multilingual website: (masterpage.master.vb)
dim pageurl string = httpcontext.current.request.url.absolutepath protected sub page_load(sender object, e system.eventargs) handles me.load dim strlanguage string = session("language") if not ispostback response.redirect(string.format("{0}?language={1}", pageurl, strlanguage)) end if response.write(string.format("{0}?idioma={1}", pageurl, strlanguage)) end sub
it display querystrings: '?language=es' or '?language=en' @ end of current url, when run web, browser displays message: page has redirect loop (err_too_many_redirects).
why happening? how can fix this?
thanks in advance
edit: tried with:
if ispostback
but when that, querystring doesn't appear @ end of url.
edit 2 (solved): works @ last! thank zed, final code follows:
dim pageurl string = httpcontext.current.request.url.absolutepath protected sub page_load(sender object, e system.eventargs) handles me.load dim strlanguage string = session("language") if not ispostback if request.querystring("language") nothing response.redirect(string.format("{0}?language={1}", pageurl, strlanguage)) end if else if not request.querystring("language") nothing response.redirect(string.format("{0}?language={1}", pageurl, strlanguage)) end if end if response.write(string.format("{0}?language={1}", pageurl, strlanguage)) end sub
you redirecting @ first page load. see:
if not ispostback response.redirect(string.format("{0}?language={1}", pageurl, strlanguage)) end if
when first visit page uses master page, redirected again, , again, , again (by way, redirection not postback)
depending on need achieve, may have make kind of check before doing redirect, or occur. ask, instance, if language
not present in querystring, , redirection:
if not ispostback if request.querystring("language") nothing response.redirect(string.format("{0}?language={1}", pageurl, strlanguage)) end if end if
Comments
Post a Comment