[英]ASP.NET Core 2.1: Razor Pages - role based authorisation not working
[英]User based authorisation not working ASP.net
尊敬的StackExchange高級會員
我正在嘗試為某些網址提供基於用戶的授權。 我已經在根目錄下配置了web.config,如下所示
<authentication mode="Forms">
<forms
name="MyAuth"
loginUrl="ABC/Login.aspx"
protection="All"
path="/"
/>
</authentication>
如下所示在ABC目錄中的另一個web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
除了輸入正確的用戶名和密碼后,即使我輸入了正確的用戶名和密碼,該頁面仍被重定向到登錄頁面本身,但除顯示登錄名外,其他一切都工作正常。
我是C#和ASP.net的新手
請幫我我在aspx.cs上的代碼如下
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string selectString = "SELECT * FROM users " + "WHERE Username = '" + Login1.UserName + "' AND Password = '" + Login1.Password + "'";
MySqlCommand mySqlCommand = new MySqlCommand(selectString,con);
con.Open();
String strResult = String.Empty;
strResult = mySqlCommand.ExecuteScalar().ToString();
con.Close();
if (strResult.Length > 0)
{
e.Authenticated = true;
Response.Redirect("up.aspx");
}
else
{
MsgBox("Wrong username or password!.", this.Page, this);
return;
}
}
請幫助我,謝謝Santosh Sharma
在您的代碼中改為使用以下代碼:
if (strResult.Length > 0)
{
FormsAuthentication.RedirectFromLoginPage
(Login1.UserName, true);
Response.Redirect("up.aspx");
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.