繁体   English   中英

ASP.NET登录自动重定向到Default.aspx

[英]ASP.NET Login Auto Redirects to Default.aspx

因此,我在ASP.NET上有一个模板登录系统,并为其创建了模板,以便可以为按钮提供CssClass。 但是,现在登录时,该登录有效,但它会自动加载已删除的defualt.aspx。 我需要添加什么来解决此问题? 我找不到会导致这种情况的任何地方,但是也许这是我没有做的事,所以它正在还原为默认设置。 更糟的是,我可以重新创建default.aspx并从那里添加一个自动重定向,除非那似乎是最不理想的。

登录页面:

<%@ Page Title="" Language="C#" MasterPageFile="~/StaticHeader.master" AutoEventWireup="true" CodeFile="login.aspx.cs" Inherits="login" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <title>in short. - Login</title>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div class="Absolute-Center">
    <asp:LoginView ID="LoginView1" runat="server">
        <AnonymousTemplate>
            <asp:Login ID="Login1" runat="server">
                <LayoutTemplate>
                    <table cellpadding="1" cellspacing="0" style="border-collapse:collapse;">
                        <tr>
                            <td>
                                <table cellpadding="0">
                                    <tr>
                                        <td align="center" colspan="2">Log In</td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="ctl08$Login1">*</asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right">
                                            <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Password:</asp:Label>
                                        </td>
                                        <td>
                                            <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
                                            <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ctl08$Login1">*</asp:RequiredFieldValidator>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <asp:CheckBox ID="RememberMe" runat="server" Text="Remember me next time." />
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="center" colspan="2" style="color:Red;">
                                            <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td align="right" colspan="2">
                                            <asp:Button ID="LoginButton" runat="server" CommandName="Login" CssClass="button" Text="Log In" ValidationGroup="ctl08$Login1" />
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </LayoutTemplate>
            </asp:Login>
            <br />
            <div style="text-align: center;">
                <a class="button" style="margin-right: 2em;" href="signup.aspx">Register</a>
                <a class="button" href="forgotpassword.aspx">Forgot Password</a>
            </div>
        </AnonymousTemplate>
        <LoggedInTemplate>
            <asp:Label ID="logOutLabel" runat="server" Text=""></asp:Label>
            <br /><br />
            <div style="text-align: center;">
                <asp:LinkButton ID="logOutButton" runat="server" class="button" OnClick="logOutButton_Click">Log Out</asp:LinkButton>
            </div>
        </LoggedInTemplate>
    </asp:LoginView>
</div>
<style>
    .Absolute-Center {
        position: absolute;
        top: 50%;
        left: 50%;
        -moz-transform: translateX(-50%) translateY(-50%);
        -webkit-transform: translateX(-50%) translateY(-50%);
        transform: translateX(-50%) translateY(-50%);
    }
</style>
</asp:Content>

我也尝试在web.config中将默认页面设置为home.aspx,但这似乎没有任何作用。

Web.config:

<configuration>

    <system.web>
      <compilation debug="true" targetFramework="4.5.2" />
      <httpRuntime targetFramework="4.5.2" />
      <authentication mode="Forms">
        <forms loginUrl="login.aspx" name=".ASPXFORMSAUTH">
        </forms>
      </authentication>
    </system.web>
    <appSettings>
      <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
    </appSettings>

    //have tried adding this
    <system.webServer>
      <defaultDocument>
        <files>
          <clear />
          <add value="home.aspx" />
        </files>
      </defaultDocument>
    </system.webServer>

</configuration>

您需要的是:

<authentication mode="forms">
<forms loginurl="login.aspx" defaulturl="[page-to-redirect-to].aspx"/>
</authentication>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM