Skip to content
This repository has been archived by the owner on Dec 8, 2018. It is now read-only.

Preserving Querystring w/ UseStatusCodePagesWithReExecute #339

Closed
tysonnero opened this issue Dec 5, 2016 · 5 comments
Closed

Preserving Querystring w/ UseStatusCodePagesWithReExecute #339

tysonnero opened this issue Dec 5, 2016 · 5 comments

Comments

@tysonnero
Copy link

Is it possible to preserve the original querystring when using UseStatusCodePagesWithReExecute. If so, will the params stay on the url or will they be stored somewhere else? If stored somewhere else :-), how are they accessed after the fact?

Thanks!

@Tratcher
Copy link
Member

Tratcher commented Dec 5, 2016

Yes, see

context.HttpContext.Features.Set<IStatusCodeReExecuteFeature>(new StatusCodeReExecuteFeature()
{
OriginalPathBase = context.HttpContext.Request.PathBase.Value,
OriginalPath = originalPath.Value,
OriginalQueryString = originalQueryString.HasValue ? originalQueryString.Value : null,
});

@tysonnero
Copy link
Author

@Tratcher Thanks for the quick response.

Do I have to upgrade to AspNetCore 1.1 for this? I am currently on 1.0.
And, how do you get at that OriginalQueryString from a Controller or View?

@Tratcher
Copy link
Member

Tratcher commented Dec 6, 2016

No, that's in 1.0. https://github.com/aspnet/Diagnostics/blob/1.0.0/src/Microsoft.AspNetCore.Diagnostics/StatusCodePage/StatusCodePagesExtensions.cs#L188
In an MVC controller you can call HttpContext.Features.Get<IStatusCodeReExecuteFeature>()

@tysonnero
Copy link
Author

I can't seem to get at OriginalQueryString b/c it's not in the IStatusCodeReExecuteFeature interface. I'm getting compile time errors.

@Tratcher
Copy link
Member

Tratcher commented Dec 6, 2016

Ah, you found a bug. The original commit (48b436e) added OriginalQueryString to StatusCodeReExecuteFeature but not to the interface IStatusCodeReExecuteFeature. You can work around this by downcasting to StatusCodeReExecuteFeature.

@muratg, as this requires a change to the interface we'll have to wait until 2.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants