我正在尝试使用以下方法解密身份验证Cookie字符串来创建FormsAuthenticationTicket对象:
Cookie securityContextCookie = cookies["myCookie"];
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(securityContextCookie.Value); // ticket returns null even with a valid encrypted cookie string
配置:
<roleManager enabled="true" defaultProvider="WebRoleProvider">
<providers>
<clear />
<add name="WebRoleProvider" type="Framework.Security.Providers.WebRoleProvider" connectionStringName="aspnetdb" applicationName="TestApp" />
</providers>
</roleManager>
<membership defaultProvider="WebMembershipProvider" userIsOnlineTimeWindow="15">
<providers>
<clear />
<add name="WebMembershipProvider" type="Framework.Security.Providers.WebMembershipProvider" connectionStringName="aspnetdb" applicationName="TestApp" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="true" requiresUniqueEmail="true" passwordFormat="Clear" />
</providers>
</membership>
<machineKey decryption="3DES" decryptionKey="..." validation="3DES" validationKey="..." />
<authentication mode="Forms">
<forms defaultUrl="dashboard" loginUrl="login" timeout="20" />
</authentication>
登录表格:
<asp:Login ID="Login1" runat="server" MembershipProvider="WebMembershipProvider"
Font-Size="13px" TextLayout="TextOnTop" LoginButtonType="Image" LoginButtonText=""
LoginButtonImageUrl="~/Content/Images/login-button.png" LabelStyle-HorizontalAlign="Left"
LoginButtonStyle-CssClass="" ToolTip="Log In" RememberMeText="Remember me?"
FailureAction="Refresh" TitleText="">
<TextBoxStyle Font-Size="13px" BorderStyle="Solid" BorderWidth="1px" Width="385px"
Height="20px" BorderColor="#e1e4ea" CssClass="login-form-textboxes" />
<LoginButtonStyle Font-Names="Verdana" />
<InstructionTextStyle Font-Italic="False" ForeColor="#464749" Font-Size="12px" />
<LabelStyle Font-Size="11px" ForeColor="#939598" Font-Bold="true" CssClass="login-form-labels" />
<TitleTextStyle Font-Bold="True" Font-Size="14px" ForeColor="#464749" />
<CheckBoxStyle CssClass="login-form-checkboxes" />
</asp:Login>
即使securityContextCookie的值看起来像一个有效的加密cookie字符串,我仍然会为票证获取null ...
知道可能导致问题的原因吗?
谢谢你的帮助