所以我用 ASP.NET (C#) 创建了一个 Web 应用程序(不是网站),它在 VS13 环境中编译得很好。但是当我在 IIS 上发布它时,默认文档上的回发失败。默认文档称为 LoginPage.aspx。只要我点击 <asp:Button>
要在后面运行我的代码,它所做的只是刷新页面。本项目暂时发布在我本地127.0.0.1 IP地址上。
我知道这是一个记录在案的问题,但我尝试了很多解决方案,但没有找到解决方案。我尝试过的一些解决方案:
- 使用最少的代码创建一个全新的 Web 应用程序以尝试访问任何回传但没有成功。
- 我尝试了此处提供的第一个解决方案但没有成功:https://stackoverflow.com/a/7367076/4204026
我还尝试了 URL 映射:
<urlMappings>
<add url="~/login" mappedUrl="~/Views/LoginPage.aspx" />
<add url="~/login/" mappedUrl="~/Views/LoginPage.aspx" />
</urlMappings>
老实说,我对这里发生的事情一头雾水。我注意到的一件事是当应用程序通过 Visual Studio 运行时,<form>
LoginPage.aspx 上的标记在 Chrome 中显示为:
<form method="post" action="LoginPage" id="ct101" class=".myForm">
通过 IIS:
<form method="post" action="./" id="ct101" class=".myForm">
也不确定这是否是个问题。我尝试对 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>
以及 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?
}
}
最后的信息:
- 运行 IIS 8.0
- 使用 4.5 Framework 创建的应用程序,应用程序池也是 4.5 Framework
- 我已确保在 IIS 上安装了 ASP.NET
- 我在 global.asax 文件中确实有 URL ReWriting,但我不确定这是否以任何方式相关(我不知道如何相关)。
- 我没有 Default.aspx 页面
编辑:
- 刚刚在 IE11 和 FF 上通过 127.0.0.1 测试项目,结果相同。
编辑#2:
我尝试过但没有成功的其他事情:
- 我尝试删除我的 URL 重写
- 我尝试添加一个空的 URL 重写规则,即
("Empty URL", "", "~/Views/LoginPage.aspx")
补充说明:
- 我不使用 Telerik
- 我不使用 ISAPI
- Visual Studio 中的项目设置为
debug
而不是release
最佳答案
我很抱歉没有在 OP 中提供足够的信息,因为我已经找到了答案。事实证明它与 ASP.NET 无关,而是与 SQL Server
有关。我剥离了代码,在一次添加一段代码并剥离所有异常处理后,我通过 IIS 发现 IIS APPPOOL\.NET vX.X
没有访问权限数据库。
我要做的是:
- 在 MSQLSM 中,为
IIS APPPOOL\.NET v4.5 添加一个新登录名
进一步,我发现它在收到以下异常后需要正确的权限才能执行某些命令:
The SELECT permission was denied on the object 'X', database 'X', schema 'dbo'
- 为新登录名授予适当的访问权限。登录属性 > 用户映射 > 检查
db_datareader
和public
。
现在执行后面的代码。它仍然留下了为什么它禁止任何回发的问题,即使我删除了后面代码中的任何 SQL 连接。很奇怪。
无论如何,感谢那些提供帮助的人。
关于c# - 默认文档回发失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27320928/