在 C# 服务器端禁用用户按钮
该页面只有 3 个文本框和 1 个按钮。
txtUser:用于用户名登录的文本框
txtPassword:用于密码登录的文本框
txtRequest:一个文本框,用户可以在其中输入他想要的所有内容
btnSubmit:一个简单的按钮,用于登录并使用 txtRequest 中输入的内容创建一个 txt 文件。
现在,我需要在用户提交请求后找到禁用该按钮的方法。 需要在第二天 00:00 之前禁用它。
示例:
我进入网页,在两个(用户名和密码)文本框中插入凭据(Active Directory 凭据),然后在另一个文本框中键入内容,然后单击“提交按钮”
我想知道..我应该实施什么?
公共分部类_default:System.Web.UI.Page { protected void Page_Load(对象发送者,EventArgs e) { } protected void btnSubmit_Click(对象发送者,EventArgs e) { var 用户名 = txtUser.Text; var oldPass = txtPassword.Text; 主体上下文_context = null; 尝试 { _context = 新的PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["域"].ToString(), ConfigurationManager.AppSettings["SearchString"].ToString(), ConfigurationManager.AppSettings["用户名"].ToString(), ConfigurationManager.AppSettings["密码"].ToString() ); UserPrincipal 用户 = UserPrincipal.FindByIdentity(_context, 用户名); 如果(用户==空) { lblError.Text = "用户名和密码不正确"; 返回; } 布尔 isOldPassValid = false; 日期时间?密码过期日期; if (user.LastPasswordSet != null) PasswordExpDate = ((DateTime)user.LastPasswordSet).AddDays(int.Parse(ConfigurationManager.AppSettings["PasswordExpiresInDays"].ToString())); 别的 密码ExpDate = new DateTime(1970, 01, 01); if ((user.LastPasswordSet == null || PasswordExpDate < DateTime.UtcNow) && !user.PasswordNeverExpires) { user.RefreshExpiredPassword(); isOldPassValid = _context.ValidateCredentials(user.SamAccountName, oldPass); user.ExpirePasswordNow(); } 别的 isOldPassValid = _context.ValidateCredentials(user.SamAccountName, oldPass); if (!isOldPassValid) { lblError.Text = "用户名和密码不正确"; 返回; } //图蒂我检查完成 字符串许可读取; 字符串允许写入; lblError.Text = "Credenziali corrette, form inviato."; /// 这里有东西 if (boxread.Checked == true) { 许可=“SI”; } 别的 { 许可=“否”; } if (boxwrite.Checked == true) { 许可写入=“SI”; } 别的 { 许可写入=“否”; } 字符串 Richiesta = txtRequest.Text; 字符串数据 = DateTime.Now.ToString(); 字符串间隔符=“-------------------------------------------------------- ------------------------------"; 字符串 docPath = "C:\\Richieste\\"; 字符串总= “[ --- RICHIESTA PERMESSI --- ]” + “
” +“
” + “[ MESSAGGIO AUTOMATICO GENERATO DAL 域控制器 DACA-I ]” + “
” + "[ Servizio richiesta permessi lettura/scrittura File-Server DACA-I ]" + "
" + “
” + “il giorno/ora:”+数据+“
” +“
” + 间隔符+“
” + “Percorso cartella:” + Richiesta + “
” +“
” + “Permessi lettura:” + permessiread + “
” + “允许书写:” + permessiwrite + “
”; 使用 (System.IO.StreamWriter outputFile = System.IO.File.AppendText(docPath + "Richieste_permessi.txt")) { 输出文件.WriteLine(间隔); outputFile.WriteLine("il giorno/ora : " + data); outputFile.WriteLine("Percorso cartella : " + Richiesta); outputFile.WriteLine("允许写入:" + permessiwrite); outputFile.WriteLine("Permessi lettura : " + permessiread); } } 捕获(密码异常 pex) { lblError.Text = "错误:" + pex.Message; } catch(异常前) { lblError.Text = string.Format("错误: {0}, {1}, {2}", ex.Message, ex.StackTrace, ex.InnerException); } 最后 { if (_context != null) _context.Dispose(); } } } }
这是我尝试过的代码的一部分..我认为这是一种愚蠢的方式,事实上它不起作用,我要打自己一巴掌,感谢任何人的支持
This page is just with 3 textboxes, and 1 button.
txtUser: TextBox for username login
txtPassword: TextBox for the password login
txtRequest: A textbox where the user can type everything he wants
btnSubmit: A simple button used for login and create a txt file with the things typed in txtRequest..
Now, i need to find a way to disable the button, after the user submitted the request.
It needs to be disabled until 00:00 of the next day..
Example:
I go on the webpage, insert credentials in the two (username and pass) TextBox (Active Directory credentials) and type something in another TextBox, then click a "Submit button"
I was wondering.. What should i implement?
public partial class _default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnSubmit_Click(object sender, EventArgs e) { var username = txtUser.Text; var oldPass = txtPassword.Text; PrincipalContext _context = null; try { _context = new PrincipalContext(ContextType.Domain, ConfigurationManager.AppSettings["Domain"].ToString(), ConfigurationManager.AppSettings["SearchString"].ToString(), ConfigurationManager.AppSettings["Username"].ToString(), ConfigurationManager.AppSettings["Password"].ToString() ); UserPrincipal user = UserPrincipal.FindByIdentity(_context, username); if (user == null) { lblError.Text = "Username e/o password non corretti"; return; } bool isOldPassValid = false; DateTime? PasswordExpDate; if (user.LastPasswordSet != null) PasswordExpDate = ((DateTime)user.LastPasswordSet).AddDays(int.Parse(ConfigurationManager.AppSettings["PasswordExpiresInDays"].ToString())); else PasswordExpDate = new DateTime(1970, 01, 01); if ((user.LastPasswordSet == null || PasswordExpDate < DateTime.UtcNow) && !user.PasswordNeverExpires) { user.RefreshExpiredPassword(); isOldPassValid = _context.ValidateCredentials(user.SamAccountName, oldPass); user.ExpirePasswordNow(); } else isOldPassValid = _context.ValidateCredentials(user.SamAccountName, oldPass); if (!isOldPassValid) { lblError.Text = "Username e/o password non corretti"; return; } //TUTTI I CHECK COMPLETI string permessiread; string permessiwrite; lblError.Text = "Credenziali corrette, form inviato."; /// SOMETHING HERE if (boxread.Checked == true) { permessiread = "SI"; } else { permessiread = "NO"; } if (boxwrite.Checked == true) { permessiwrite = "SI"; } else { permessiwrite = "NO"; } string Richiesta = txtRequest.Text; string data = DateTime.Now.ToString(); string spacer = "---------------------------------------------------------------------------"; string docPath = "C:\\Richieste\\"; string tot = "[ --- RICHIESTA PERMESSI --- ]" + "</br>" + "</br>" + "[ MESSAGGIO AUTOMATICO GENERATO DAL DOMAIN CONTROLLER DACA-I ]" + "</br>" + "[ Servizio richiesta permessi lettura/scrittura File-Server DACA-I ]" + "</br>" + "</br>" + "il giorno/ora : " + data + "</br>" + "</br>" + spacer + "</br>" + "Percorso cartella: " + Richiesta + "</br>" + "</br>" + "Permessi lettura: " + permessiread + "</br>" + "Permessi scrittura: " + permessiwrite + "</br>"; using (System.IO.StreamWriter outputFile = System.IO.File.AppendText(docPath + "Richieste_permessi.txt")) { outputFile.WriteLine(spacer); outputFile.WriteLine("il giorno/ora : " + data); outputFile.WriteLine("Percorso cartella : " + Richiesta); outputFile.WriteLine("Permessi scrittura : " + permessiwrite); outputFile.WriteLine("Permessi lettura : " + permessiread); } } catch (PasswordException pex) { lblError.Text = "Error: " + pex.Message; } catch (Exception ex) { lblError.Text = string.Format("Errore: {0}, {1}, {2}", ex.Message, ex.StackTrace, ex.InnerException); } finally { if (_context != null) _context.Dispose(); } } } }
That's a part of the code i tried.. and i think that's a stupid way tho, in fact it didn't work and i am gonna slap my-self, thanks for the support anyone
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种方法:
密码更新 -> DateTime
DateTime.Now
btnSubmit_Click
密码更新事件上,查询数据库并检查该值。如果
PasswordUpdateOn.AddDays(1) <= DateTime.Now
然后禁用文本框。This is one way to do it:
PasswordUpdatedOn -> DateTime
DateTime.Now
btnSubmit_Click
Password update event, query the DB and check for this value. If
PasswordUpdateOn.AddDays(1) <= DateTime.Now
then Disable the text box.