3

バックオフィスアプリケーションとして使用されるASP.NETMVCアプリケーションに認証Cookieを送信するASP.NETアプリケーションがあります。

認証Cookieのすべてのコントローラーアクションをチェックするグローバルフィルターを追加しました。Cookieが存在する場合、ユーザーはページに入ることができます。

コードは次のようになります。

 public class SecurityFilter : FilterAttribute, IAuthorizationFilter
    {
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            // TODO: For some reason .AUTHCookie cookie isn't exist in request context of filter,

                           HttpCookie cookie = filterContext.RequestContext.HttpContext.Request.Cookies[".AUTHCookie "];


            if (cookie != null)                 {

Application_BeginRequest反対側からは、Global.asaxファイルのイベントでASP.NETアプリケーションから送信されたCookieを確認できます。

クッキーが消えた場所と理由は?MVCリクエスト処理パイプラインのどの部分でCookieが破棄されましたか?

  protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var cookies = HttpContext.Current.Request.Cookies;
            // HERE I CAN SEE BOTH cookies. In filter action only one cookie was found. The authentication cookie is thrown somewhere ...
        }  
4

1 に答える 1

3

私のシナリオの解決策を見つけました。両方のアプリケーションの machinekey に compatibilityMode="Framework45" を追加しましたが、すべて完全に機能しています。

注: アプリケーションの 1 つが古いバージョンの .NET Framework を使用している場合、以前のマシン互換モードを使用するように .NET 4.5 アプリを明示的に構成する必要があります。そうしないと、フォーム認証チケットを暗号化/復号化できなくなります。

私のシナリオを思い出してください:

WebForms ASP.NET 4.5

<machineKey compatibilityMode="Framework45" decryption="AES" validation="SHA1" decryptionKey="your_key1" validationKey="your_keu2" />
  <authentication mode="Forms">
    <forms name="_authcookie" domain=".domain.com" loginUrl="Default.aspx?View=1" defaultUrl="Default.aspx?View=1" timeout="30" path="/" protection="All" slidingExpiration="true" enableCrossAppRedirects="true" />
  </authentication>

MVC 4
<machineKey compatibilityMode="Framework45" decryption="AES" validation="SHA1" decryptionKey="your_key1" validationKey="your_keu2" />
   <authentication mode="Forms">
     <forms name="_authcookie" domain=".domain.com" defaultUrl="~/" timeout="30" path="/" protection="All" slidingExpiration="true" enableCrossAppRedirects="true" />
    </authentication>

互換モードの可能な値:

http://msdn.microsoft.com/en-us/library/system.web.configuration.machinekeysection.compatibilitymode.aspx

于 2013-06-27T03:34:20.650 に答える