3

最初に私が言いたいのは: はい、私の質問と似ていても同じではない質問がたくさんあることは知っています。

開発者マシンで 12 のサイトの 1 つを開始すると、すべてがうまく機能し、サーバーでも 11 のサイトが問題なく動作します。

12 番目のサイトを開始すると、最初は正常に動作しますが、ポストバック (ボタン、AutoPostBack を使用した DropDownList など) が発生すると、次のエラーが発生します。

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   Infoscreen.Anzeigeeinstellungen.Page_Load(Object sender, EventArgs e) in C:\Users\Krusty\Desktop\Schule\Diplomarbeit\Infoscreen\Infoscreen\Anzeigeeinstellungen.aspx.cs:97
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +24
   System.Web.UI.Control.LoadRecursive() +70
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3047

パス (C:\Users\Krusty\Desktop\Schule\Diplomarbeit\Infoscreen\Infoscreen\Anzeigeeinstellungen.aspx.cs) は、ファイルが私の開発者マシンにあったパスです。しかし、なぜ??プログラムにパスをハードコーディングしたことはなく、サイトを再作成しても機能しませんでした。

何をすればよいでしょうか?ヒント/ヒントをいただければ幸いです。

編集:

91    if (!Page.IsPostBack)
92    { 
93        Response.Cookies["Infoscreen_Anzeigeeinstellungen_Ausgewählte_Abteilung"].Value =  ausgewählte_Abteilung.ToString(); 
94    }
95    else
96    { 
97        ausgewählte_Abteilung = Request.Cookies["Infoscreen_Anzeigeeinstellungen_Ausgewählte_Abteilung"].Value; 
98    }

編集:

はい、IIS は Cookie を使用するように構成されています

編集:

解決しました!VisualStudio2010サーバーでは、文字「ä」は機能します...
IIS7では機能しません...
そのため、Cookieが適切に設定されず、getリクエストがハングアップします

Cookieに「Infoscreen_Anzeigeeinstellungen_Ausgewaehlte_Abteilung」という名前を付けましたが、現在は正常に動作しています

閉じることができます

4

1 に答える 1

2

あなたはすでに自分自身を知っていますが、将来の参考のために:

Cookie を処理するためのコードでは、c# で「名前」を使用できますが (a-umlaut を使用)、RFC2616 に従って、Cookie のトークンには US-ASCII 文字のサブセットを含める必要があります。

if (!Page.IsPostBack)
    { 
        Response.Cookies["Infoscreen_Anzeigeeinstellungen_Ausgewählte_Abteilung"].Value =  ausgewählte_Abteilung.ToString(); 
    }
    else
    { 
        ausgewählte_Abteilung = Request.Cookies["Infoscreen_Anzeigeeinstellungen_Ausgewählte_Abteilung"].Value; 
    }

したがって、cookiekey が form/controlnames に基づいて生成される場合に安全な Cookies キーを取得する方法は次のようになります。

static string TokenRFC2616(string key)
{
    const string separators = "()|<>@,;:\\\"/[]?={} ";
    var chars = from ch in key.Normalize(NormalizationForm.FormD)
            where CharUnicodeInfo.GetUnicodeCategory(ch) 
                     != UnicodeCategory.NonSpacingMark &&
                  separators.IndexOf(ch)==-1
            select ch;
    return String.Concat(chars);
}

string cookiekey = TokenRFC2616(
       "Infoscreen_Anzeigeeinstellungen_Ausgewählte_Abteilung");
if (!Page.IsPostBack)
{ 
   Response.Cookies[cookieKey].Value =  ausgewählte_Abteilung.ToString(); 
}
else
{ 
    ausgewählte_Abteilung = Request.Cookies[cookieKey].Value; 
}

(上記のサンプルでは、​​Cookie 名は になりますInfoscreen_Anzeigeeinstellungen_Ausgewahlte_Abteilung )

于 2013-10-13T14:25:30.847 に答える