I am trying to set a session variable in an action method in MVC5, but it is giving compile-time error as shown above.
My Question: How can i correctly set a session variable in this case? Session is enabled in web config.
Controller name is OrdersController and action method is GetOrders.
I just found that this is too simple and I was missing it.
All that is needed to set a session variable in an action method is code like below.
Session["ColumnFilters"] = "somevalue";
Related
I am newly initiated backend devloper. I am working with sailsJS [MVC Framework of Nodejs].
I am having one confusion regarding session access and flow in sailsJS. Please help me to clear this.
I am saving my user in session in AdminController, which i had create using CLI service of sailsJS. But I am not able to use that variable in another controller : InventoryContoller in the same application.I was in impression that session is something that we can use in whole application from anywhere.
I created session in one of app controller : AaminController as follow:
req.session.user = user;
But i am not able to access this session variable outside the AdminController.
I want to use this variable inside whole applicaiton.
When I am injecting a RxHttpClient in micronaut, I have an url with a token that I want to get from an environment variable to avoid hardcoding a secret.
In my service, I have injected the client like this:
#Client('${System.getenv(\'BOT_URL\')}')
#Inject
RxHttpClient httpClient
Being BOT_URL my url that's stored in an environment variable.
The project build but it fails while trying to use the client with this error:
2021-03-20 20:05:14.37 Could not resolve placeholder ${System.getenv('BOT_KEY')}
My variable is correctly defined in the server, how can I access to it when injecting the client?
Micronaut ships with pre-made PropertySourceLoaders that will resolve PropertySources from different sources. You can read more on externalized configuration through the docs.
Besides these PropertySourceLoaders, PropertySources are resolved from environment variables and are automatically injected and available for use within the ApplicationContext following the property source key syntax:
i.e. SOME_ENVIRONMENT_VARIABLE translates to some.environment.variable
Hence you can simply inject your HttpClient declaratively with the environment variable key translated to dot-separated-property-key syntax:
#Client('${bot.url}')
#Inject
RxHttpClient httpClient
You should be able to access environment variables just using ${BOT_URL}. I know for a fact that this works in the application.yml file. If it doesn't work in the annotation you can always create a property in application.yml with the value of the environment variable and use the property in your annotation.
For the docs on this, try the "Property value binding" section of the micronaut docs.
I'm using passport for my nodejs application, the session is working fine, I can access to my Object user from my views thanks to my global variable 'res.locals.user = req.user', but when I attempt to access to it from a javascript file located in my public folder/javascripts/file.js, my object user is not defined there.
Thank you in advance.
That's because is a server variable and you can only acces it within your teamplate. One solution is to create a variable in to global scope in your template and later use it in your js file.
For example if you are using jade, in your template you can do :
script.
var myVar = !{myVar};
script(src='yourScript')
To be very specific: If I get the managed object context from the app delegate and do not set any parameters on it, what happens when running inserts, updates followed by save()?
Does the app block on save() until done?
Yes, the save method blocks. It's not even a default-- that's how it is, always. Does't matter if the context came from the app delegate or somewhere else, save is a synchronous method.
This what it came down to:
Normally, when I create an object, I only set the main key (properties that don't change through the lifecycle of the object) on creation. I then use an update method to complete the creation. In this particular case, I changed one property on the server from 'creational' property to 'updateable' property, but I missed it in the app. So the app was deleting the objects only to have the server create them again a bit later...
What is the default scope of xp:dominoDocument data source?
Sven Hasselbach posted an answer to another question, where he says that you have to set the scope of the data source to request scope and his answer solves the problem:
How can I refresh the XPages File Download Control and have it display updated attachments without full page refresh?
My experience with the default scope of the xp:dominoDocument data source is, that the default scope is the request scope. I am working with managed beans and managed properties. When I inject a xp:dominoDocument data source as a managed property in a managed bean then I have to set the scope of this managed bean to request scope.
Otherwise (e.g. managed bean scope is set to view) I get the following error:
27.05.2015 13:04:55 HTTP JVM: Managedbean fileUploadHandler could not be created The scope of the referenced object:
'#{currentDocument}' is shorter than the referring object. For more
detailed information, please consult error-log-0.xml located in
d:/Lotus/Domino/d
Yes, dominoDocument and dominoView are scoped to request, as Mark Leusink's Debug Toolbar from OpenNTF confirms.
If you want to use a datasource, it may be easier to avoid using a managed property. You can still add the datasource to the page, but access it via ExtLibUtil.resolveVariable(ExtLibUtil.getXspContext().getFacesContext(), "document1"); or navigate down to it from its container. Alternatively, you may be able to use managed properties for the document UNID, form etc, and instantiate a com.ibm.xsp.model.domino.DominoDocumentData in the bean's constructor or after a check for null in the getter.
A data source object will always sit in the request scope. What you are changing is the behaviour of the data container of the datasource, which is in the view scope by default.
When using the Debug Toolbar, you can see the behaviour: Even if you set the data source's scope to application scope, you still find the data source in the request scope. But also you will find a DominoDocumentDataContainer instance in the application scope.
If you are set the scope to request, the data container is also in the request scope. That's why the "file upload trick" works.