简体   繁体   中英

Ways to avoid user from accessing page with querystring

I have a page that I want it to be accessed when the user finishes saving the form. I have a Response.Redirect("MyPage.aspx?queryStringParam=123") (the value chages, based on field selection) .

On the page I have a check to see if the value is being passed and everything is working:

if (Request.QueryString["queryStringParam"] != null)
{
    int queryStringParam;
    if(int.TryParse(Request.QueryString["queryStringParam"], out id))
    {
        hfQueryStringParam.Value = queryStringParam.ToString();
    }
    else
    {
        Response.Redirect(ResolveUrl("~/Default.aspx"));
    }
}
else
{
    Response.Redirect(ResolveUrl("~/Default.aspx"));
}

If the user tryes to type the page, it checks for the queryString and if it's not being passed, it will redirect him to the default page, but hte problem is, if he types the queryStringParam into the url, the page will load. I don't want that to happen.

Is there any way to block the user from accessing the page by typing the url and only access it with Response.Redirect ?

From the page where you are saving the form,store something in the session just before the redirection to MyPage.aspx. In the MyPage.aspx first check for the session value. If it does not have a value which you set from the previous page, redirect the user to the default page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM