开发者

RedirectUrl info lost after doing postback in client-side code

My login page works like this: when you enter it, javascript reads some info from you, writes it into some input and does submit so that the read data can be read and processed on server.

<script language="开发者_如何学JAVAjavaScript" type="text/javascript">
    function getUserInfo() 
    {
            var userInfo = xyz.GetSecureBox();
            form1.info.value = userInfo;
            form1.read.value = "true";
            form1.submit();
    }
</script>

Server code authenticates user or not, depending on the provided data.

The problem is that when you try to enter a different page, let's make it Default.aspx, you are redirected to login page with RedirectUrl parameter so that you can be authenticated. But after postback made i javascript the RedirectUrl information is lost. How can I preserve it?

Well I can of course read that query string parameter in js and write it into some input. How can I access query string parameters in JS? And maybe there is a different way?


The only other way I can think of is using session and/or cookie.

If using querystring and parse it in JS, you have to code it yourself. There are lots of codes out there doing this. E.g.
Ask Ben: Getting Query String Values In JavaScript
jQuery Query String Object


My idea was to write the query string parameter to the session on server side, so that I can easily read it on server after postback.

Session["ReturnUrl"] = Request.QueryString["ReturnUrl"];  

This appeared to be the easiest way.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜