简体   繁体   中英

Query String Parameter Being Lost on Request

i'm developing an MVC 4 web application.

I'm trying to make an url that changes in an authorized/unauthorized context.

I'm generating the following url for unauthorized user:

http://localhost/vendas-web/Login?ReturnUrl=%2Fvendas-web%2FClienteNovo%2FIndex%299999

The first time I've tested, it worked just fine.

But.. the second time I've tried, the query string got lost.. and the url turned into:

http://localhost/vendas-web/Login

When i test it against chrome on anonymous tab, it works FINE. When i change the value of the last parameter, it works FINE.

There's some sort of cache related to this ?

What i'm doing wrong ?

Soo, my question is:

How do i keep my full url in any scenario ??

Ty

There's really not enough information here, but what you're likely talking about is that the first time a user needs to be authorized, they are automatically redirected to the first URL, which includes the ReturnUrl bit. That's built into the framework to allow the user to be redirected back to that URL after logging in. However, if you need to persist this past that initial first redirect to the login page, that's on you. Any links must manually add the query string param:

@Url.Action("SomeAction", new { ReturnUrl = Request["ReturnUrl"] })

And any forms must include it as a hidden input:

@Html.Hidden("ReturnUrl", Request["ReturnUrl"])

Otherwise, yes, it will be lost, because the literal URL you're now requesting doesn't include it. It's not just magically appended.

My problem was cache...

I've used this annotation to avoid using cache by application.

[OutputCache(NoStore = true, Duration = 0)]

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