开发者

Redirect from JavaScript

开发者 https://www.devze.com 2023-04-10 10:33 出处:网络
I\'m working on an internal web app and we are using secure query string keys generated server side for some simple security to prevent users from accessing pages they haven\'t been given access to.Th

I'm working on an internal web app and we are using secure query string keys generated server side for some simple security to prevent users from accessing pages they haven't been given access to. The page I am currently working on grabs data via AJAX calls and renders it in a table on the page. Each row has an edit button that will take the user to an edit page with more information, with the id of the row kept in the query string. Since every row id is unique, the key for every edit page will be unique to that row-user combination.

My problem is that I need to be able to get these secure query string keys from the server in some way that allows the JavaScript to redirect the user. I can't move the key generator client side because that opens up the possibility of users generating their own keys for pages they don't have permission to visit. And similarly I can't expose the generator in a web ser开发者_运维技巧vice.

Basically what this boils down to is I am stumped in finding a way to send data from the client to the server in order to generate a secure key and then redirect the user to the new page.

Not exactly sure if I am being 100% clear but I'll edit this as questions come in.


Your question is a little unclear, but PageMethods might work for this:

[WebMethod]
public static string GetSecureID()
{
    return "Secure";
}

clientRedirectSecure = function() {
    PageMethods.GetSecureID(onSuccess, onFailure);
} 
onSuccess = function(result) {
    window.location.href = "somepage.aspx?id=" + result;
} 
onFailure = function(error) {
    alert(error);
} 

Here's an article that discusses PageMethods:
http://blogs.microsoft.co.il/blogs/gilf/archive/2008/10/04/asp-net-ajax-pagemethods.aspx

0

精彩评论

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

关注公众号