2011-01-31 75 views
0

私は実際に迷惑な問題に遭遇しました。このエラーは「指定されたキーが辞書に存在しませんでした」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); 
    } 

CONFIGURATION

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> 
+0

コードでインデクサーを使用して多数のオブジェクトにアクセスしていますが、例外をスローしている行を教えてください。 –

+0

@Steve Dannerこの行:WSInstance.InternetInstance()。PublishNews(news); – diceler

答えて

1

エラーは、サイトのゾーンをIisSettings辞書で見つけることができないことを示しています。 Zoneプロパティの値とIisSettingsディクショナリの内容の両方をチェックする必要があります。 RunWithElevatedPrivilegesの外側にあるIisSettingsにアクセスするので、それらはあなたが期待する値を含んでいないかもしれません。エンドユーザーのアクセス権が必要です。

ウェブアプリケーションが多くのサイトコレクションとサイトをホストしているため、web.configのアプリケーション設定を保存することはSharePointの最良の選択肢ではありません。それを変更すると、すべてのサイトが再起動して再コンパイルされます。

Sharepoint 2010ガイダンスのApplication Settings Managerセクションで、適切なサイトのプロパティバッグに設定を保存する別の方法を確認してください。

0

Saw Steveさんからのコメントは、エラーが発生している場所へのポインタがあれば良いことに同意します。これはSilverlight(またはWPF)ですか?その場合は、XAMLで使用したスタイリング名が辞書に存在しないことがあります。名前を慎重に確認し、ここに問題があるかどうかを判断してください。

どちらも可能です。コードを実行すると、命名の問題が頻繁に失われます。

+0

これは、SharePoint 2010 Silverlightフレームワークに読み込まれるページです。しかし、私が言及したように、controlapplicationスクリプトを実行して記事のすべての日付を変更する前に、すべてうまくいきました。 – diceler

+0

ところで、コードブロック内を水平にスクロールすると、どこにエラーが発生したかを示すコメントが表示されます。 – diceler

関連する問題