Dre*_*edy 9 c# asp.net iis postback
所以我用ASP.NET(C#)创建了一个Web应用程序(不是Web站点),它在VS13环境中编译得很好.但是当我在IIS上发布它时,默认文档上的回发失败.默认文档称为LoginPage.aspx.只要我点击<asp:Button>后面运行我的代码,它所做的就是刷新页面.该项目暂时在我当地的127.0.0.1 IP地址上发布.
我知道这是一个记录在案的问题,但我尝试了许多解决方案并且没有遇到过解决方案.我试过的一些解决方案:
我也尝试过URL映射:
<urlMappings>
<add url="~/login" mappedUrl="~/Views/LoginPage.aspx" />
<add url="~/login/" mappedUrl="~/Views/LoginPage.aspx" />
</urlMappings>
Run Code Online (Sandbox Code Playgroud)
老实说,我不知道这里发生了什么.我注意到的一件事是当应用程序通过Visual Studio运行<form>时,LoginPage.aspx上的标记在Chrome中显示为:
<form method="post" action="LoginPage" id="ct101" class=".myForm">
Run Code Online (Sandbox Code Playgroud)
通过IIS:
<form method="post" action="./" id="ct101" class=".myForm">
Run Code Online (Sandbox Code Playgroud)
不确定这是否也是一个问题.我试着硬编码action来login看看会发生什么,它重定向到正确的页面,但怀疑是回发被解雇了-我的Session变量返回null,并没有使用查询字符串.
这是相关的LoginPage.aspx前端代码(修剪了一堆不相关的HTML):
<%@ Page Title="DREW KENNEDY | WELCOME" Language="C#" MasterPageFile="Site.Master" AutoEventWireup="true" CodeBehind="LoginPage.aspx.cs" Inherits="MyMedia.Views.LoginPage" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<!-- form is located on Site.Master -->
<asp:Button OnClick="LoginBtn_Click" CssClass="login" runat="server" name="submit" Text="Sign In" />
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
和LoginPage.aspx.cs中的LoginBtn_Click方法:
protected void LoginBtn_Click(object sender, EventArgs e) {
//Tried the following line while commenting out everything else to make sure Postback is being ignored
//Response.Write("<script>alert('Test');</script>");
try {
AbstractPersistenceDecorator decorator = new PersistenceDecorator();
string uname = username.Text.Trim();//username is a TextBox Control
string pass = password.Text.Trim();//password is a TextBox control
bool isCookieRequested = CheckBox.Checked;
if (decorator.authenticate(uname, pass)) {//calling SQL Server for authentication
User AuthenticatedUser = (User)Session["User"] ?? decorator.getUserInfo(uname);
if (Session["User"] == null) Session["User"] = AuthenticatedUser;
if (isCookieRequested) {
HttpCookie cookie = new HttpCookie("username", AuthenticatedUser.Username);
cookie.Expires.AddDays(7);
Response.Cookies.Add(cookie);
} else {
Session.Timeout = 15;
}
Thread.Sleep(1600);
//string redirect = string.Format("dashboard?username={0}", AuthenticatedUser.Username);
Response.Redirect("dashboard?username=" + AuthenticatedUser.Username);
}
} catch (Exception ex) {
//who cares?
}
}
Run Code Online (Sandbox Code Playgroud)
最后的信息:
编辑:
编辑#2:
我试过的其他事情没有成功:
("Empty URL", "", "~/Views/LoginPage.aspx")补充说明:
debug和不release我很抱歉没有在OP中提供足够的信息,因为我已经找到了答案。事实证明它与 ASP.NET 无关,而是与SQL Server. 我剥离了代码,然后一次添加回一段代码并剥离了所有异常处理,我通过 IIS 发现IIS APPPOOL\.NET vX.X没有访问数据库的权限。
我必须做的是:
IIS APPPOOL\.NET v4.5此外,我发现在收到以下异常后需要正确的权限才能执行某些命令:
对对象“X”、数据库“X”、架构“dbo”的 SELECT 权限被拒绝
db_datareader和public。现在执行后面的代码。即使我删除了后面代码中的任何 SQL 连接,它仍然留下了为什么它禁止任何回发的问题。很奇怪。
不管怎样,感谢那些帮助过的人。