我们有两个在IIS 8.5上运行的ASP.NET(4.0)Web应用程序。用户将定期尝试登录,并在提交凭据后将其重新加载到白屏。
响应大小为0字节,状态为200。登录页面将重新加载并显示HTML,但是当您提交表单时,将显示白页。回收应用程序池后即可解决。
我已经检查了IIS日志和事件查看器,没有与此问题相关的错误或警告。
login.aspx页面的代码如下:
<%@ Page Title="" Language="C#" MasterPageFile="~/login.Master" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="Driver.login1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<style type="text/css">
.has-error {
color: red;
}
</style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div class="form-group">
<span id="spnInvalidAccount" runat="server" visible="false" class="has-error">Invalid Credentials</span>
</div>
<div class="form-group has-feedback">
<asp:TextBox TextMode="SingleLine" ID="txtEmail" CssClass="form-control" placeholder="Box Number" runat="server"></asp:TextBox>
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" CssClass="has-error" ControlToValidate="txtEmail" ErrorMessage="Careem Id Required" Display="Dynamic"></asp:RequiredFieldValidator>
</div>
<div class="form-group has-feedback">
<asp:TextBox ID="txtPassword" runat="server" CssClass="form-control" TextMode="Password" placeholder="Password"></asp:TextBox>
<span class="glyphicon glyphicon-lock form-control-feedback"></span>
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" CssClass="has-error" ControlToValidate="txtPassword" ErrorMessage="Password Required" Display="Dynamic"></asp:RequiredFieldValidator>
</div>
<div class="row">
<!-- /.col -->
<div class="col-xs-8">
<span class="checkbox">
<div class="icheckbox_flat-red col-xs-1" aria-checked="false" aria-disabled="false" style="position: relative;">
<%--<asp:CheckBox ID="cbxRememberMe" runat="server" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;" />--%>
<input id="Login1_RememberMe" runat="server" type="checkbox" name="Login1$RememberMe" style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255); border: 0px; opacity: 0;">
</div>
<label for="Login1_RememberMe" class="col-xs-9">Remember me</label>
</span>
</div>
<div class="col-xs-4">
<asp:Button ID="btnSubmit" Text="Sign In" runat="server" CssClass="btn btn-primary btn-block btn-flat" OnClick="btnSubmit_Click" />
</div>
<!-- /.col -->
</div>
</asp:Content>
以及背后的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Driver
{
public partial class login1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["action"] != null && Request.QueryString["action"] == "logout")
{
HttpCookie loggedInCookie = new HttpCookie("LoggedIn");
loggedInCookie.Expires = DateTime.Now.AddDays(-1);
Response.Cookies.Add(loggedInCookie);
}
else if (Request.Cookies["LoggedIn"] != null && Request.Cookies["LoggedIn"].Value != null)
{
Response.Redirect("default.aspx");
}
}
if (Request.Cookies["LoggedIn"] != null && Request.Cookies["LoggedIn"].Value != null)
{
Response.Redirect("default.aspx");
}
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
using (DriverEntities cnx = new DriverEntities())
{
string password = Global.EncryptPassword(txtPassword.Text);
if (cnx.Drivers.Where(x => x.BoxNumber == txtEmail.Text && x.Password == password).Any())
{
Driver driver = cnx.Drivers.FirstOrDefault(x => x.BoxNumber == txtEmail.Text && x.Password == password);
Car car = cnx.Cars.FirstOrDefault(x => x.Id == driver.CarId);
HttpCookie loggedInCookie = new HttpCookie("LoggedIn");
loggedInCookie.Value = driver.Id.ToString();
if (!Login1_RememberMe.Checked)
loggedInCookie.Expires = DateTime.Now.AddHours(8);
else
loggedInCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(loggedInCookie);
HttpCookie carCookie = new HttpCookie("MV_car");
carCookie.Value = car.Id.ToString();
Response.Cookies.Add(carCookie);
DateTime currentDate = DateTime.Now.AddDays(-1);
Response.Redirect("default.aspx");
}
else
{
spnInvalidAccount.Visible = true;
}
}
}
}
}
一些说明: -我无法在本地重新创建此问题。这仅在生产环境中发生。 -我们将相同的登录页面用于许多其他应用程序,但它们没有遇到相同的问题。 -该页面未重定向到default.aspx页面。 -Customerrors已关闭,因此如果出现应用程序错误,我们将能够看到异常屏幕