ホスティング会社で直面している問題があります。私は FormsAuthentication を使用するプロジェクトを使用しています。問題は、正常にログインしても非常にすぐにログアウトすることです。その原因は何なのかわかりません。だから私のweb.configファイルに私はそれらの行を追加しました:
<authentication mode="Forms" >
<forms name="Nadim" loginUrl="Login.aspx" defaultUrl="Default.aspx" protection="All" path="/" requireSSL="false"/>
</authentication>
<authorization>
<deny users ="?" />
</authorization>
<sessionState mode="StateServer" stateConnectionString="tcpip=localhost:42424" cookieless="false" timeout="1440">
</sessionState>
これは、カスタムログインページで使用するコードです:
protected void PasswordCustomValidator_ServerValidate(object source, ServerValidateEventArgs args)
{
try
{
UsersSqlDataSource.SelectParameters.Clear();
UsersSqlDataSource.SelectCommand = "Select * From Admins Where AdminID='" + IDTextBox.Text + "' and Password='" + PassTextBox.Text + "'";
UsersSqlDataSource.SelectCommandType = SqlDataSourceCommandType.Text;
UsersSqlDataSource.DataSourceMode = SqlDataSourceMode.DataReader;
reader = (SqlDataReader)UsersSqlDataSource.Select(DataSourceSelectArguments.Empty);
if (reader.HasRows)
{
reader.Read();
if (RememberCheckBox.Checked == true)
Page.Response.Cookies["Admin"].Expires = DateTime.Now.AddDays(5);
args.IsValid = true;
string userData = "ApplicationSpecific data for this user.";
FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket(1, IDTextBox.Text, System.DateTime.Now, System.DateTime.Now.AddMinutes(30), true, userData, FormsAuthentication.FormsCookiePath);
string encTicket = FormsAuthentication.Encrypt(ticket1);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
Response.Redirect(FormsAuthentication.GetRedirectUrl(IDTextBox.Text, RememberCheckBox.Checked));
//FormsAuthentication.RedirectFromLoginPage(IDTextBox.Text, RememberCheckBox.Checked);
}
else
args.IsValid = false;
}
catch (SqlException ex)
{
ErrorLabel.Text = ex.Message;
}
catch (InvalidOperationException)
{
args.IsValid = false;
}
catch (Exception ex)
{
ErrorLabel.Text = ex.Message;
}
また、次のコード行も見つかります。 FormsAuthentication.RedirectFromLoginPage(IDTextBox.Text, RememberCheckBox.Checked); ログイン時にチケットに何か問題があるのではないかと思ったので、手動で作成しましたが、私が試したことがわかっていることはすべて試しましたが、何も機能しませんでした。前もってありがとう、Baher。