Sitecore LinkManager ExpandDynamicLinks does not resolve the site URL - c#

I am having a problem with the ExpandDynamicLinks in Sitecore.
I am using the following method passing true for siteResolving. The problem is the site is not being resolved as promissed.
bodyExpandedLinks = Sitecore.Links.LinkManager.ExpandDynamicLinks(email.Body.Value, true);
I did set in my provider to never resolve the site because that is what I want for the whole site except for this email body above.
alwaysIncludeServerUrl="false"
Does anybody know how to force that?
Thank you...

I know this post is tagged with sitecore7, but I would like to share a solution for Sitecore 8.1. I don't know if it works for 7 or not. It is adapted from Sitecore.Links.LinkProvider.ExpandDynamicLinks():
var linkParser = new LinkProvider.LinkParser();
var urlOptions = LinkManager.Provider.GetDefaultUrlOptions(); // returns a clone.
urlOptions.SiteResolving = true;
urlOptions.AlwaysIncludeServerUrl = true;
text = linkParser.ExpandDynamicLinks(text, urlOptions);
This does not work for media links because Sitecore.Links.DynamicLink.BuildMediaUrl() and Sitecore.Links.MediaLinkExpander.Expand() completely ignore their UrlOptions parameter. If you need full media urls, wrap your code with this:
using (new SettingsSwitcher("Media.AlwaysIncludeServerUrl", "true"))
{
phrase = linkParser.ExpandDynamicLinks(phrase, urlOptions);
}

one option might be to check if AlwaysIncludeServerUrl is set to False before your call to ExpandDynamicLinks. If it's False you can explicitly call Sitecore.Links.UrlOptions.DefaultOptions.AlwaysIncludeServerUrl = true and then set it back to False after you have called ExpandDynamicLinks.

I found an alternative method.
I did add a extra link provider, with the same configurations but the alwaysIncludeServerUrl which I set to true.
<add name="sitecore_expandlinks" alwaysIncludeServerUrl="true" (...) >
Then I got the provider using the API.
bodyExpandedLinks = Sitecore.Links.LinkManager.Providers["sitecore_expandlinks"].ExpandDynamicLinks(email.Body.Value, true);
If someone else has a more cohesive option I would much appreciate
Thanks.

Related

LUIS returning only one intent

I am working on a small project with LUIS integration. I am using the using Microsoft.Bot.Builder.Luis namespace for communication with the api. i was inspecting all intents i got back but since last week i only get back one intent per luis-call. Is there any (by me) unseen change to the verbose mode i did not get? Is there a way to still call for all intentresults or giving the luismodel some kind of settings on its way to the server?
i did not change any settings on luis.ai and i was wondering why this happens. Thanks in advance!
meq
This worked for me. In the LuisRecognizer constructor there is an optional parameter with a flag called IncludeAllIntents. Just set it to true and add it to the constructor.
var luisApplication = new LuisApplication(
configuration["LuisAppId"],
configuration["LuisAPIKey"],
"https://" + configuration["LuisAPIHostName"]);
var predictionOptions = new LuisPredictionOptions();
predictionOptions.IncludeAllIntents = true;
_recognizer = new LuisRecognizer(luisApplication, predictionOptions);
Generally, LUIS still returns an array of intents with the result set so there must be something specific going on with your model.
If further experiments don't determine the cause, contact us at luservice#microsoft.com with your LUIS App Id and we can investigate.
I am assuming you are using LuisDialog, you need to set Verbose = true to get all the intents.
public RootLuisDialog() : base(new LuisService(new LuisModelAttribute(
Settings.Default.LuisAppId,
Settings.Default.LuisAPIKey,
domain: Settings.Default.LuisAPIHostName
)
{
Verbose =true,
Log = true
}))
{
}

Azure Notification Hub installation not updating tags

I am attempting to update the tags of an installation within Azure Notification Hub after registration. I am following several guides for this, notably here and here.
Both of these guides suggest that the following code should work however it is plainly not; the tag never gets updated. There are no errors, and I can guarantee that the installationId is correct. I am guessing I am setting the path/value of the tag incorrectly.
// in constructor:
var _notificationHub = NotificationHubClient.CreateClientFromConnectionString(Settings.ConnectionStrings.NotificationHub, Settings.Defaults.NotificationHubName);
// in WebApi endpoint:
var installationUpdates = new List<PartialUpdateOperation>();
var userDetail = _userDetailRepo.Get(id);
installationUpdates.Add(new PartialUpdateOperation
{
Operation = UpdateOperationType.Replace,
Path = "/tags/interestedin", // is this incorrect?
Value = interestedIn.ToUpper()
});
userDetail.InterestedIn = interestedIn;
await Task.WhenAll(
_userDetailRepo.InsertOrReplace(userDetail),
_notificationHub.PatchInstallationAsync(installationId, installationUpdates));
Here is the installation object's tags, as per VS:
I also tried hardcoding the path to Path = "/tags/interestedin:W" but it made no difference.
Can someone tell me if I am doing something wrong here, and if so how I should amend my code. Thanks.
Unfortunately, Path = "/tags/interestedin" is not going to work as of now. We are currently working on wildcards' support. Once it is done, something like "/tags/interestedin*" will work fine for you.
While Path = "/tags/interestedin:W" should be OK. If you could provide namespace name, hub name, and a timeframe, then I'll take a look at logs to check what is going on there.

Adding a Fix version using JIRA SOAP API

I am trying to use the JIRA SOAP API to add a fix version to an issue. I know that similar questions have been asked before, but I still cannot get it to work. Here is the link to the most relevant question, in case someone can make better use of the information there than I can:
jirasoapservice and Fix Version
I feel like I am doing everyting correct but the fix version is never added. As the answer to the above question says, I do not set an ID and I have made sure that the name is correct by looking at the project's getVersions array.
I am using C#. Thanks for any advice. A working code snippet in C# would be very helpful.
I turns out that you can update this field as you would any other field:
RemoteFieldValue v = new RemoteFieldValue
{
id = "fixVersions",
values = new String[] { wi.Fields[29].Value.ToString() }
};
List<RemoteFieldValue> actionParams = new List<RemoteFieldValue>();
actionParams.Add(v);
jiraSoapServiceService.updateIssue(token, key, actionParams.ToArray());

Redirect in MVC does not work as expected

I have the following code:
var redirectIp = string.Format("{0}{1}", Session["CurrentHost"], ip.PathAndQuery);
return new RedirectResult(redirectIp);
When I check the value of redirectIP it gives me:
redirectIp "127.0.0.1:84/Administration/Accounts/ShowSummary?ds=0001" string
However when I step through the code the browser opens and gives me the following:
http://127.0.0.1:84/Administration/Accounts/127.0.0.1:84/Administration/Accounts/ShowSummary?ds=0001
I am totally confused. Anyone have any idea what's happening?
That is how urls, http and browsers work. You forgot the protocol part, so the redirect actually does work as expected, given the url that you are redirecting to.
var redirectIp = string.Format("http://{0}{1}", Session["CurrentHost"], ip.PathAndQuery);
return new RedirectResult(redirectIp);
This will work better for now, but to be able to also cover https, you're better off storing the protocol part in a session variable along with the hostname.

Why can't I delete this cookie?

Okay, here is the 411 - I have the following event handler in my Global.asax.cs file:
private void Global_PostRequestHandlerExecute(object sender, EventArgs e)
{
if (/* logic that determines that this is an ajax call */)
{
// we want to set a cookie
Response.Cookies.Add(new HttpCookie("MyCookie", "true"));
}
}
That handler will run during Ajax requests (as a result of the Ajax framework I am using), as well as at other times - the condition of the if statement filters out non-Ajax events, and works just fine (it isn't relevant here, so I didn't include it for brevity's sake).
It suffices us to say that this works just fine - the cookie is set, I am able to read it on the client, and all is well up to that point.
Now for the part that drives me nuts.
Here is the JavaScript function I am using to delete the cookie:
function deleteCookie(name) {
var cookieDate = new Date();
cookieDate.setTime(cookieDate.getTime() - 1);
document.cookie = (name + "=; expires=" + cookieDate.toGMTString());
}
So, of course, at some point after the cookie is set, I delete it like so:
deleteCookie("MyCookie");
Only, that doesn't do the job; the cookie still exists. So, anyone know why?
you have to delete your cookie at the same path where you created it.
so create your cookie with path=/ and delte it with path=/ as well..
Have you checked the client-side and server-side cookie domains and paths to ensure they're the same?
Is one cookie secure and the other not?
Other than that, I would suspect server/client clock sync issues, as Erlend suggests.
Weird.. The code you pasted is almost verbatim to this: http://www.quirksmode.org/js/cookies.html which works fine..
I know you are using Ajax, but have you tried quickly knocking it to server side code to see if that works? This may help in figuring if it is a problem with the JS or something else (e.g mystery file locking on the cookie)?
Update
Just had a quick Google, looks like there may be issues with browser settings as well. I don't think your problem is the code here, it's more likely to be something else. I would suggest try the above as PoC and we can move from there. :)
I posted a js cookie util a week or so ago on my blog. This has worked for me on all "A Grade" browsers.
var CookieUtil = {
createCookie:function(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
},
readCookie:function(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
},
eraseCookie:function(name) {
createCookie(name,"",-1);
}
};
Have you tried to use ;expires=Thu, 01-Jan-1970 00:00:01 GMT?
Also if a cookie domain was specified during the creation, I've found that you must also specify the cookie domain while trying to delete (expire) it.
Are we sure there's no code that sets the Cookie to HttpOnly (we're not missing anything above)? The HttpOnly property will stop (modern) browsers from modifying the cookie. I'd be interested to see if you can kill it server side like Rob suggests.
I assume you are calling this javascript on the browser side. Which browser are you using, how are you viewing the cookie to confirm it is still there?

Categories