What's the best way in ASP.NET Core MVC to globally persist the querystring parameters? For instance, let's say I have "?t=1" in the URL. I would like that parameter to persist when clicking any link within the application. I would like to avoid controller or view specific code as this needs to be global. Can I use a Middleware for something like this?
Asked
Active
Viewed 1,028 times
1
-
Please don't use the MVC6 tags, it's now named "ASP.NET Core MVC" – Tseng Oct 24 '16 at 16:18
1 Answers
0
Query string values are read-only in terms of request/responses. You cannot set the query string for a response other than redirecting to a URL with the query string included.
Technically: there is no Query
property on a HttpContext.Response
, only in the Request
.
You should either make sure to add the query string value to every URL on your website, or use another state mechanism such as TempData or session state to persist values across requests. This can easily be implemented using middleware.

Community
- 1
- 1

Henk Mollema
- 44,194
- 12
- 93
- 104
-
The app is completely stateless, so storing state is not an option. I wonder if the best best is to somehow override the anchor tag helper. – Tyson Nero Oct 24 '16 at 18:21
-
@GrandMasterT if I'm not mistaken it's possible to configure the temp data provider to use a cookie for persisting data which keeps your application stateless. I'm not sure on the details though. – Henk Mollema Oct 24 '16 at 18:26