We use the Cache object as a flag to identify if a certain username is already logged in.
System.Web.HttpContext.Current.Cache.Insert(SessionObjects.CurrentUserId.ToString(), Session.SessionID);
There is a action filter which basically checks if this item exists in the cache. If it does then the user is logged out
However sometimes I'm finding this object miraculously disappears and causes null exceptions when trying to retrieve it from the cache within the action filter.
I notice we don't seem to specify any expiration/ dependency specifics. Given the sample code above, are there any conditions where .net could of removed this entry for me without my permission?
Related
I a using the exact code here https://developers.sendinblue.com/reference/addcontacttolist-1 to add a user to a list. It all works, user is created/updated (if exists) then the user is added to the list. However, when adding to the list it throws an error.
Error calling AddContactToList:
{"code":"invalid_parameter","message":"Contact already in list and/or
does not exist"}
Their code shows a display result in JSON which will never get hit because it throws at the Add method.
The error is straight-forward. The contact is already in the list and the API enforces uniqueness.
You can get the contacts that are already in the list via getContactsFromList
https://developers.sendinblue.com/reference/getcontactsfromlist
or contact details via getContactInfo:
https://developers.sendinblue.com/reference/getcontactinfo-1
So, you will need to check whether the contact is already in the list. If so, then don't add it. Otherwise, you can add it without problems.
I've been trying to use the TSqlModel method DeleteObjects to programmatically remove certain users from a Database project. The problem is that when I call the method, the user remains in the model. I wonder if I am calling the method correctly. Here's something close to what I am doing:
modelFromDacpac.DeleteObjects(#"DOMAIN\user");
When I run the following code to see if it's really gone, the user is still there!
var tst_delete= modelFromDacpac.GetObjects(User.TypeClass, new ObjectIdentifier(#"DOMAIN\user"), DacQueryScopes.Default).FirstOrDefault();
tst_delete is non-null and has a name that matches "DOMAIN\user".
Any idea what I'm doing wrong?
Prior to the DeleteObject method call, I insert the following line - where the sqlobj object is a TSqlObject referring to the user I am trying to delete
//For some reason, the logins aren't scripted objects within the DACPAC, and so cannot be deleted using the DeleteObjects method - or maybe they simply cannot be found.
modelFromDacpac.ConvertToScriptedObject(sqlobj, "DOMAIN_user.sql");
Then I call the DeleteObject method as follows:
modelFromDacpac.DeleteObjects("DOMAIN_user.sql");
I'm not sure why this works, but it does. My guess is that the DeleteObject method is pretty picky about how and where it expects to find objects. Or, maybe some objects, like users, are stored in some non-standard fashion which prevents DeleteObjects from finding them. Whatever the reason, but explicitly converting the user to a scripted object with a given name, and passing that given name to the DeleteObjects method, it works.
I am a little concerned that I do not know why it works. The other concern is that it doesn't show up in the official documentation of the TSqlModel object:
https://msdn.microsoft.com/en-us/library/microsoft.sqlserver.dac.model.tsqlmodel_methods(v=sql.120).aspx
But it does work. At least, so far.
DeleteObject caught me out the same way :) - it only deletes scripts added using AddOrUpdate when you also pass in a script name and Delete uses the same script name.
What you need to do is create a new model and add in everything except the things you want to delete.
Why do you want to delete a login? If you don't want it to be deployed you can use a deployment contributor like my one here to exclude the login at deployment time:
https://the.agilesql.club/Blogs/Ed-Elliott/HOWTO-Filter-Dacpac-Deployments
Ed
I'm trying to test if items can be viewed by an anonymous user:
var anon = User.FromName("domain\\Anonymous");
if (item.Security.CanRead(anonymousUser))
return true;
But it always returns true, even when I know that for particular items, they must have a certain role to view it, as I can see from the access viewer:
The responsible crawler -which actually executes ComputeFieldValue code- is designed in such way to wrap this code in a SecurityDisabler. That is why it is not possible inside a computed field to verify whether has access to the field or not.
Sitecore does recommend to do the security check during the search (ootb) but indeed the TotalResults do not match if you do - which sucks ;)
If you would try to get security in the index - first try to find a solution for keeping the item security updated. E.g. if you would break inheritance somewhere, how would your index know what items to update? ...
May sound like a dumb question but here goes.
I instantiate a LIST from my homepage, the list is in a global class file, and returns all the information about the person logging in. the person, could have one or more accounts associated with the site, and therefore i need to code against a default flag to display their default account informaiton. However, i then also need to build their other account information and display this for them.
The additional account(s) are listed in a drop down box. when the drop down box fires off, instead of calling out to the class again, and retrieving all the necessary information, as i've already done this once, how can i store the object, so that it can be used?
I've looked at Session Variables, but this gets a bit messy (I have 35 fields being returned in my list), plus, the Session variables only get set the first time around, not on DDL changed.
therefore, I need a way of having quick access to the object. - what's the best approach?
As per me , Session is the best possible object for your type of requirement and on DDL changed event try to rebind the Session object with new modified values
I'm writing a workflow that needs to perform certain actions depending on which fields are changed when someone edit's an item. For example, if a user goes in and removes a role (job) from an item (staff member) then I need the workflow to realise that the role field was changed, deduce which role was removed (or potentially added) and then notify the manager of that role and do any other necessary tasks. Another example would be if the address fields in an item get changed then the appropiate HR department need to be notified of the change.
To do this I'm going to try a code block when the workflow is started that compares the top two history entries and any fields that differ will be flagged as changed and I'll take the appropriate actions dependent on each field.
Could anyone please tell me what the other options are for getting this functionality as I'd like to know if there's a better way. Thanks
Using SPD workflows it would not be that hard, depending on number of roles.
Create a column and then go into the content type and hide it. Create a SPD workflow that executes on new or change. Compare the hidden column and the one the user entered, if changed compare values against a role name and do what needs to be done. When that is done copy the user entered column into the hidden column.
Ugly and long but if you don't have the abaility to get workflow code implemented on the server, thanks corporate IT, then it is an option.
I would enable versioning on the list and then use:
SPListItem currentItem = workflowProperties.Item;
SPListItemVersion previousItemVersion = currentItem.Versions[1];
//Compare the fields in currentItem and previousItemVersion
But if i understand your question correctly, that’s what you’re about to do already.