How to clear the query string after I already got the values I want?

Asked

Viewed 563 times

-2

I’m using Asp.net c#, and I wanted to clear the query string so it doesn’t look for the user, for example "http://meusite.com.br/Pagina1.aspx?parametro=Lucas"..... I take this name and use it in my code when on pageLoad, but I would like it to be not visible to the user.

  • If you can’t redirect after using the variable, there is no way. If so, I put as answer.

  • Hello, from what I saw in this link is possible yes using the function window.history.pushState, there is also this article

  • 2

    Lucas, try using a friendly URL. Has a link that shows you how to do this. http://www.devmedia.com.br/conceitos-e-exemplo-url-amigaveis-em-asp-net/23270

  • worked out the friendly URL, thanks !

  • You use this parameter so that even?

1 answer

0

Hello,

use following Javascript code

//pega a url atual, remove o query string e altera a url
var pageObj = {"html":"","pageTitle":""};
window.history.pushState(pageObj ,"", window.location.href.split('?')[0]);

url is the last parameter, and left defined by

window.location.href.split('?')[0]

The object passed in the first parameter can have the following items

perform this after saving (or include on output after taking the data in C#)

Source

  • This will cause a redirect on the page, right?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.