LoggedInTemplate不显示

时间:2013-09-04 21:24:38

标签: c# asp.net-membership

我正在使用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>

该网站有一个具有LoginView控件的MasterPage

 <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?

0 个答案:

没有答案