Я столкнулся с действительно раздражающей проблемой, которая дает мне эту ошибку: «Данный ключ отсутствовал в словаре».Проблема с Web.config - данный ключ отсутствовал в словаре
То, что я не понимаю, заключается в том, что он отлично работал в соответствии с прошлой пятницей и днями до этого. Я отлаживал, проверял, нет ли файлов webservice и т. Д. Все это подходит.
Все, что я делал в прошлую пятницу, выполнял скрипт, который проходил через все элементы в моем списке, который содержит страницы статей и редактировал дату их создания. Я не знаю, могло ли это что-то изменить, но это единственное, что я могу вспомнить.
ASPX.CS
protected void Page_Load(object sender, EventArgs e)
{
var listId = Request.QueryString["ListID"];
var itemId = Request.QueryString["ItemID"];
try
{
var spList = SPContext.Current.Web.Lists[new Guid(listId)];
var item = spList.GetItemById(int.Parse(itemId));
var image = (ImageFieldValue)item["PublishingPageImage"];
var contentType = (string)item["ContentType"];
var pageLayout = (string) item["PublishingPageLayout"];
var news = new News
{
Title = (string)item["Title"],
NewsId = item.UniqueId,
Content = (string)item["PublishingPageContent"],
ArticleDate = item["ArticleStartDate"] == null ? DateTime.Now : (DateTime)item["ArticleStartDate"],
PageName = item.File.Name,
Author = new SPFieldUserValue(SPContext.Current.Web, (string)item["Author"]).User.LoginName,
IsArticle = contentType.Contains("Article"),
PageLayout = GetLayout(pageLayout),
Image = GetImage(image)
};
// Jumps to the WSInstance class.
WSInstance.InternetInstance().PublishNews(news); // This line throws the exception.
lblMessage.Text = "News '<i>" + news.Title + "</i>' have been published succesfully to the Internet site.";
}
catch (Exception ex)
{
EventLogger.LogError("Error occured while publishing news: " + ex.Message + "\n" + ex.StackTrace, this);
}
}
WSINSTANCE
public static WSIntegration InternetInstance(SPSite spSite)
{
// Jumps to the Configuration class.
var url = Configuration.GetConfigurationValue("Progressive.WS.Internet", spSite);
...
return new WSIntegration
{
Credentials = new NetworkCredential(username, password, domain),
Url = url
};
}
public static WSIntegration InternetInstance()
{
return InternetInstance(SPContext.Current.Site);
}
КОНФИГУРАЦИИ
public static class Configuration
{
public static string GetConfigurationValue(string key, SPSite site)
{
var name = site.WebApplication.IisSettings[site.Zone].ServerComment; // This is where it fails and throws the error: "The given key was not present in the dictionary."
var value = "";
SPSecurity.RunWithElevatedPrivileges(() => { value = WebConfigurationManager.OpenWebConfiguration("/", name).AppSettings.Settings[key].Value; });
return value;
}
}
Раздел, в котором он получает данные из файла web.config.
<appSettings><add key="Progressive.WS.Internet" value="http://shpt02/_layouts/DR/WSIntegration.asmx" /> // This is the key value it cannot find.
<add key="Progressive.WS.Internet.Username" value="user" />
<add key="Progressive.WS.Internet.Password" value="password" />
<add key="Progressive.WS.Internet.Domain" value="domain" /></appSettings>
Вы получаете доступ ко многим объектам с индексаторами в своем коде, можете ли вы рассказать нам, какая строка выбрасывает исключение? –
@Steve Danner Эта строка: WSInstance.InternetInstance(). PublishNews (новости); – diceler