hi,
my requirement is like below:
need to pass browser date time to controller to calculate data based on browser date.
its a huge application and due to lack of time cant pass as param to each page..
is there any idea of passing a param to the welcome and holding that in appsetting like that..
please share me the idea on that..
thanks in advance to all who spent time on this
Murali PPosted Aug 3, 2023, 12:30 PM
thank you so much sir for ur quick reply..
if possible could u please let me know the idea of the below point:
Brahma Prakash ShuklaPosted Aug 3, 2023, 11:49 AM
If I understand your requirement correctly, you want to pass the browser's date and time to the server-side controller so that you can use it to calculate data based on that date. You are looking for a way to achieve this without passing the date as a parameter to each page in your application.
One way to achieve this is by using a middleware or a filter in your web application to intercept the incoming request, extract the browser's date and time, and store it in a place accessible to the controller. One possible approach is to use a custom header to pass the browser's date and time in the request.
Here's a step-by-step approach:
Example using JavaScript with Axios library:
Example middleware in ASP.NET Core:
Register Middleware in Startup.cs: In your
Startup.csfile, add the middleware to the pipeline.Access in Controllers: Now you can access the browser's date and time from the
HttpContext.Itemscollection in your controllers or services.This way, you can pass the browser's date and time to the server-side controller without explicitly passing it as a parameter to each page.
Remember to handle error scenarios and validations based on your application's specific requirements.