0

我正在使用 ASP.Net Membership 来处理我们网站的登录。我们在 SQL Server 上设置了表,这是 Web.config

 <connectionStrings>
<add name="OurWorldLoginEntities" connectionString="metadata=res://*/OurWorld.csdl|res://*/OurWorld.ssdl|res://*/OurWorld.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=localhost\localinstance;initial catalog=OurWorldLogin;integrated security=True;multipleactiveresultsets=True;application name=EntityFramework&quot;" providerName="System.Data.EntityClient" />
<add name="OurWorld" connectionString="data source=localhost\localinstance;initial catalog=OurWorldLogin;integrated security=True;" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
<machineKey validationKey="5256BC27E9181A907DC7962870585DD622CD41ABB636020F0642AA238C0AA3B1614D367F62DBD51F5B3D7EB5734F4EC3915F957EC0C2E01152EE48D24FDEA721" decryptionKey="BEA903A316F9CF06C0739C4AB9075EF97F0C2B05C8129FB8" validation="SHA1"/>
<profile enabled="true" automaticSaveEnabled="true" defaultProvider="SqlProfileProvider">
  <providers>
    <add name="SqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="OurWorld" applicationName="Inside.leadingRE.com" />
  </providers>
</profile>
<membership defaultProvider="SqlMembershipProvider">
  <providers>
    <add name="SqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="OurWorld"
         minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0" enablePasswordRetrieval="true" enablePasswordReset="true"
         requiresQuestionAndAnswer="false" requiresUniqueEmail="false" passwordFormat="Encrypted" maxInvalidPasswordAttempts="10" passwordAttemptWindow="30"
         applicationName="Inside.leadingRE.com" passwordStrengthRegularExpression="" />
  </providers>
</membership>
<roleManager defaultProvider="SqlRoleProvider" enabled="true" cacheRolesInCookie="true" cookieName=".ASPROLES"
             cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true"
             cookieProtection="All">
  <providers>
    <add name="SqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="OurWorld"
         applicationName="Inside.LeadingRE.com" />
  </providers>
</roleManager>
</system.web>

该站点有一个 MasterPage,其中包含 LoginView 控件

 <table cellpadding="0" cellspacing="0" border="0" align="center" style="width: 100%">

        <asp:LoginView ID="lv_LoginView" runat="server">
            <AnonymousTemplate>
                <tr>
                    <td align="center">
                        <asp:ContentPlaceHolder ID="ContentPlaceHolderAnonymous" runat="server"></asp:ContentPlaceHolder>
                    </td>
                </tr>
            </AnonymousTemplate>
            <LoggedInTemplate>
                <tr>
                    <td>
                        <asp:ContentPlaceHolder ID="ContentPlaceHolderLoggedIn" runat="server"></asp:ContentPlaceHolder>
                    </td>
                </tr>
            </LoggedInTemplate>
        </asp:LoginView>
    </table>

Login.aspx 页面有一个用户 id 和密码字段,成功登录后会将用户发送到我有此页面的 Default.aspx

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolderAnonymous" runat="server">
Not Logged In
</asp:Content>
 <asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolderLoggedIn"      runat="server">
     Logged In
</asp:Content>

问题是我被引导到那里,但匿名模板只显示。我不确定这里发生了什么,因为它几乎是 MSDN 演练中的复制/粘贴。

附带说明一下,有没有办法不重定向到 Default.aspx,但如果登录成功,则留在同一页面上,而只显示 LoggedInTemplate?

4

0 回答 0