SPWeb.CurrentUser.RegionalSettings.TimeZone is null - sharepoint-2013

I have a code
SPWeb web = SPContext.Current.Web;
SPTimeZone tz = web.CurrentUser.RegionalSettings.TimeZone;
It works fine for 350 users. Only 2 show error on the second line:
Object reference not set to an instance of an object
All our users have their Time zone set in Profile service. the same as the 2 that error.
Anyone has an idea why it is?
Thank you

I suggest you run the "User Profile service application proxy - User Profile to SharePoint language and region synchronization" time job again and then check if it works.
And we can use the REST API below to check the profile properties of the 2 users , and check if "SPS-TimeZone" is null.
/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=#v)?#v='domain\user'
To avoid the issue in the code, I suggest you use the code below.
SPWeb web = SPContext.Current.Web;
SPTimeZone tz;
if (web.CurrentUser.RegionalSettings != null)
{
tz = web.CurrentUser.RegionalSettings.TimeZone;
}
else if (web.RegionalSettings != null)
{
tz = web.RegionalSettings.TimeZone;
}
else
{
tz = SPRegionalSettings.GlobalTimeZones[web.Site.WebApplication.DefaultTimeZone];
}

Related

Getting .NET Core, WS Federation, Identity Core Issue with TicketDataFormat

I have two applications that are using WS Federation and I am working to migrate one of these applications over to .NET Core. These two applications need to be able to share cookies and this is where I am running into an issue on the .NET Core side.
This is a portion of my Startup.cs
services.AddIdentity<ApplicationUser, ApplicationRole>()
.AddEntityFrameworkStores<Context>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options =>
{
options.LoginPath = new PathString("/Account/Login");
//LOGIN WORKS CORRECTLY WITH THE BELOW LINE COMMENTED
options.TicketDataFormat = new AuthTicketDataFormat();
options.Cookie.Name = "cookiename";
options.Cookie.Path = "/";
options.Cookie.Domain = "";
});
services.ConfigureExternalCookie(options => {
options.LoginPath = new PathString("/Account/Login");
//LOGIN WORKS CORRECTLY WITH THE BELOW LINE COMMENTED
options.TicketDataFormat = new AuthTicketDataFormat();
options.Cookie.Name = "cookiename";
options.Cookie.Path = "/";
options.Cookie.Domain = "";
});
services.AddAuthentication()
.AddWsFederation(options => {
// MetadataAddress represents the Active Directory instance used to authenticate users.
options.MetadataAddress = authentication.GetValue<string>("AdfsWsFedMetadataUri");
// Wtrealm is the app's identifier in the Active Directory instance.
// For ADFS, use the relying party's identifier, its WS-Federation Passive protocol URL:
options.Wtrealm = authentication.GetValue<string>("AdfsRelyingPartyIdentifier");
});
I am able to see that I do receive a cookie in the Network tab, but the issue I am having is that I am being put into an infinite loop because on my anonymous Callback endpoint I have the following:
var loginInfo = await this._signInManager.GetExternalLoginInfoAsync();
//loginInfo is always coming back as null
if (loginInfo == null) {
return RedirectToAction("Login");
}
It seems the issue is being caused by options.TicketDataFormat and creating a custom format for the cookie. The cookie seems to be created correctly with the ticketDataFormat, but getExternalLoginInfoAsync on signInManager is always returning null.
Any help or direction is greatly appreciated as I've been banging my head against the wall for a day trying to figure this out.

Can a loadrequest cause "WF: === Starting WebFilter logging for process"?

My app is just a quiz app and does not access the web or use any web view
The error message starts with:
WF: === Starting WebFilter logging for process XXXXXXXXXXX
2017-01-23 22:16:14.120062 XXXXXXXXXXX[533:58517] WF: _userSettingsForUser mobile:
{
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
Then the error message is listed for several times:WF: _WebFilterIsActive returning: NO
the app then runs out of memory
The error messages appear seemingly after:
[self.interstitial loadRequest:[GADRequest request]];
Please help
The Mobile Ads SDK team believes this is nothing to worry about:
This seems to be iOS10+ specific and should not affect ad serving in any way.

Commerce Server with Sitecore - how to update orders status

May I ask how to update orders status with Sitecore Commerce 8 powered by Commerce Server. Or in sitecore 7.2 if possible.
Based on the class Sitecore.Commerce.Connect.CommerceServer.Orders.Models.CommerceOrder class, we tried to save StatusCode as "InProcess" but it was not updated.
CartServiceProvider provider = new CartServiceProvider();
var orderRequest = new SubmitVisitorOrderRequest(buyCart);
var orderResult = orderService.SubmitVisitorOrder(orderRequest);
var order = orderResult.Order as CommerceOrder;
order.StatusCode = "InProcess";
provider.SaveCart(new SaveCartRequest(order));
We have tried the code below but got an error.
https://social.msdn.microsoft.com/Forums/en-US/a4e74c33-cf4f-4a1b-843c-acf2514db3f2/how-to-update-purchase-order-status?forum=commserver2009#44ff5a5e-b6af-4b82-aebe-1c53beff9f5c
We modified the code to update status as admin
OrderSiteAgent orderAgent = new OrderSiteAgent("website", true, "");
Error : on line OrderManagementContext context = OrderManagementContext.Create(ordersAgent);
There was a problem reading the site resources from the Commerce Server administration database for the site 'website'. Please check that resources exist for the site and that the process has permission to access the database. The InnerException contains more details.

How to call processing page via web service

I have a processing page and I want to run function process all via web service (add web reference into my C# window form app). My code below:
var context = new ModuleABCService.Screen() // limk web services: http://localhost:8686/soap/DMSBL009.asmx
{
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
EnableDecompression = true,
Timeout = 60000
};
var loginResult = context.Login(string.Format("{0}#{1}", val.UserName, company), val.Password);
if (loginResult.Code != ErrorCode.OK)
{
throw new Exception(string.Format("Can not login {0}", company));
}
Content content = context.GetSchema();
context.Clear();
context.Submit(
new Command[]
{
content.Actions.ProcessAll
}
);
And I got an exception message:
System.Web.Services.Protocols.SoapExceptio:n Server was unable to process request. ---> PX.Data.PXUndefinedCompanyException: Unable determine proper company id for the request. at PX.Data.PXDatabaseProviderBase.getCompanyID(String tableName, companySetting& setting) in c:\Builders\4_10-2014_4_28-21_21_17-Full\Scripts\BuildTemp\NetTools\PX.Data\Database\Common\DbProviderBaseCompanies.cs:line 471...
Have you ever got this error before? Could you please give me any suggestion? Thank you so much!
Ok, I found out, because Acumatica's license

TermSet Creation gives error in SharePoint 2013 using custom webservice

I am trying to create a new term set in SharePoint 2013 using a custom WCF web service deployed within SharePoint 2013 server. I have written below code to create the term set.
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (Impersonator imp = new Impersonator("Username", "Domain", "Password"))
{
using (SPSite site = new SPSite("http://server:8002/sites/site/"))
{
site.AllowUnsafeUpdates = true;
TaxonomySession session = new TaxonomySession(site);
TermStore termStore = session.TermStores["Managed Metadata Service"];
var termStoreAdmin = termStore.TermStoreAdministrators.Where(obj => obj.PrincipalName.Contains("domain\\username")).FirstOrDefault();
if (termStoreAdmin == null)
termStore.AddTermStoreAdministrator("domain\\username");
Group group = termStore.GetGroup(new Guid(groupGuid));
if (group != null && !string.IsNullOrEmpty(termSetName))
{
TermSet termset = group.TermSets.FirstOrDefault(obj => obj.Name.Equals(termSetName));
if (termset == null)
{
termset = group.CreateTermSet(termSetName);
termSetGuid = termset.Id.ToString();
}
SetupNavTermSet(termset, session, site.OpenWeb());
}
termStore.CommitAll();
}
}
});
I am calling this method from silverlight code using soap message. While calling this code I am getting exception while executing group.CreateTermSet(termSetName); line.
The error is:
Error Message : Value cannot be null.
Source : Microsoft.SharePoint
Error Details : at Microsoft.SharePoint.Administration.Claims.SPClaimProviderManager.GetUserIdentifierEncodedClaim(IIdentity identity)
at Microsoft.SharePoint.Taxonomy.Internal.CommonUtilities.GetCurrentUserName()
at Microsoft.SharePoint.Taxonomy.TaxonomySession.get_CurrentUserName()
at Microsoft.SharePoint.Taxonomy.Group.CreateTermSet(String name, Guid newTermSetId, Int32 lcid)
at Microsoft.SharePoint.Taxonomy.Group.CreateTermSet(String name)
at SplitVisionMetadataManagement.CustomManageMetaDataWCFService.<>c__DisplayClassc.<CreateTaxonomyTermSet>b__8()
Has anybody got this issue and a solution?
I also encountered the same issue and figured out that the Microsoft.SharePoint.Taxonomy.Internal.CommonUtilities.GetCurrentUserName() method uses the HttpContext.Current.User security principal for arriving at the user name.
I am using similar code in a windows form application and hence the HttpContext was empty. I made a workaround by setting the context and user manually as below.
if (HttpContext.Current == null)
{
HttpRequest request = new HttpRequest("", SiteURL, "");
HttpContext.Current = new HttpContext(request, new HttpResponse(TextWriter.Null));
HttpContext.Current.User = System.Threading.Thread.CurrentPrincipal;
}
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SiteURL))
{
using (SPWeb web = site.OpenWeb())
{
if (HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
// Your SharePoint Term Creation code
}
}
});
In your case it seems like you are using claims based authentication and hence some issue with the claims provider in returning the name. You HTTP context would be the context under which the WCF is running. You may need to investigate further in those angle.
The above knowledge should help you to understand it further.