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

本文关键字:Default aspx 重定向 NET 登录 ASP | 更新日期: 2023-09-27 18:03:31

所以我有一个模板登录系统的ASP。我把它做成一个模板,这样我就可以给按钮一个CssClass。但是现在当我登录,登录工作,但它会自动加载默认。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中的Aspx。

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

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

你需要的是:

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