我得到:
在我将我的网站发布到 IIS 服务器之后,在我使用正确的凭据按下登录按钮之后。它在我的本地机器上运行良好,应该将我转移到ControlPanel.aspx
页面。
登录按钮代码:
protected void BtnSubmitClick(object sender, EventArgs e)
{
using (var db = new DbContext())
{
if (db.Users.Any(x => x.Username == txtUserName.Text && x.Password == txtPassword.Text))
{
FormsAuthentication.RedirectFromLoginPage(txtUserName.Text, true);
}
else
{
ClientScript.RegisterStartupScript(GetType(), "myalert", "alert('* invalid credentials, please try again');", true);
}
}
}
我认为这可能与 web.config 有关:
<?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="Login.aspx">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="Styles">
<system.web>
<authorization>
<allow users="?" />
</authorization>
</system.web>
</location>
<location path="ControlPanel.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 loginUrl="Login.aspx" defaultUrl="ControlPanel.aspx" />
</authentication>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<customErrors mode="Off"></customErrors>
</system.web>
<connectionStrings>
<add name="DbContext" connectionString="metadata=res://*/db.csdl|res://*/db.ssdl|res://*/db.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.***\SQLEXPRESS;initial catalog=Portal;persist security info=True;user id=sa;password=****;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>