在我的 default.aspx 上是一个登录页面:
默认.aspx:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Portal.Default"
MasterPageFile="Portal.Master" Title="Login" %>
<asp:Content runat="server" ContentPlaceHolderID="MainContentPlaceHolder">
<div class="block" id="login">
<h2>Login</h2>
<asp:Label style="top: 15px;left: 11px" runat="server" Text="User Name :" CssClass="label" />
<asp:TextBox ID="txtLoginUserName" Style="top: 15px;left: 17px; width:100px" runat="server" CssClass="textbox" />
<asp:Label style="top: 20px;left: 19px;" runat="server" Text="Password :" CssClass="label" />
<asp:TextBox ID="txtLoginPassword" Style="top: 20px;left: 25px; width:100px;" runat="server" TextMode="Password" CssClass="textbox" />
<asp:Button ID="btnLogin" Style="top:30px;left: 91px" CssClass="button" runat="server" Text="Login" OnClick="BtnSubmitClick" />
</div>
</asp:Content>
后面的代码:
using System;
using System.Linq;
using System.Web.Security;
namespace Portal
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Page.Form.DefaultFocus = txtLoginUserName.ClientID;
}
protected void BtnSubmitClick(object sender, EventArgs e)
{
using (var db = new DbContext())
{
if (db.Users.Any(x => x.Username == txtLoginUserName.Text && x.Password == txtLoginPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtLoginUserName.Text, true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('* invalid credentials, please try again');", true);
}
}
}
}
}
网络配置:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<location path="default.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="Styles">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="Console.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<location path="Options.aspx">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>
<system.web>
<authorization>
<deny users="?" />
</authorization>
<authentication mode="Forms">
<forms name="Portal" loginUrl="default.aspx" defaultUrl="console.aspx" />
</authentication>
...
</system.web>
</configuration>
问题是当我访问我的网站时,http://www.myhostname.com/default.aspx
它没有带我去http://myhostname.com/default.aspx?ReturnUrl=%2f
哪个奇怪的地方,所以我输入用户名和密码,点击登录...一切都变成空白...网址更改为http://www.myhostname.com
,我输入所有内容第二次...之后它登录...并转到console.aspx
为什么这样做?