问题描述:

Later update

So, spent some time trying to figure this out and I got to this:

In sitecore.config there is a section where you define your websites. While I was trying to setup a custom login page I added "loginPage" attribute to "website" site element but it didn't work.

At one point I realized that I have to change the name from "website" to "myhost_name" and the login page started to work as expected but it turns out that removing the "website" site element wasn't a very bright idea because the website started to have this unstable behavior.

Does anyone know what's the right setup for this situation? I don't find the Sitecore documentation to clear in this matter.

Thanks


I have the following issue (I'm kind of new in Sitecore development so it might be some easy stuff, but I can't figure it out)

I have a template for some error messages I will show in the website and I have a folder under content where I store this Items

There are 3 fields I added on template:

- Type

- ResultKey

- Message

All of them are Single Line Text

Now, in visual studio I have a routine which does this:

/// <summary>

/// Get an Item by path

/// </summary>

public Item GetItemByPath(string itemPath)

{

return Sitecore.Context.Database.GetItem(itemPath);

}

And I have an other one which should return a ViewModel

public ModelValidation GetMessageByName(string itemName, string xpath)

{

var mess = GetItemByPath(xpath + itemName);

if (mess == null) return new ModelValidation(3, itemName);

int type;

string stype = "";

string message = "";

mess.Fields.ReadAll();

if (mess.Fields["Type"] == null)

stype = "3";

else

stype = mess.Fields["Type"].Value;

if (!int.TryParse(stype, out type))

type = 3;

if (String.IsNullOrEmpty(mess.Fields["Message"].Value))

message = itemName;

else

message = mess.Fields["Message"].Value;

return new ModelValidation(type, message);

}

The issue:

The item is returned, all the fields are in place, but the value of my fields is "" (String.Empty)

What am I doing wrong ?

The items have values in Sitecore and they are published ( I checked the Web database)

Context

Sitecore 8.1

VS 2013 MVC 5.2.3

Thank you

网友答案:

Below are the possibilities of getting the empty results.

  1. Language Version is not passed properly while fetching the item.
  2. The path of the item might be incorrect
  3. The Context database might be wrong, the data might be in master but you are referring Web database.
  4. Try using to fetch the item by Item ID.
  5. There might be different versions for the same item and you light be fetching the wrong Version which has empty values
网友答案:

try to change your query into: return Sitecore.Context.Database.GetItem(itemPath, Sitecore.Context.Language); If you didn't specify the language the returned item can be in different language than you have in context and because of that your data is empty.

Best regards, Łukasz Skowroński

网友答案:

Thank you all for your advices. The problem was that there was an other site config file . Stil does not explain the unexpected behavior but at least I solved the issue.

相关阅读:
Top