I am making a page that the user should enter his password again to open and when he navigate away and come back again he should re-enter the password. NO SESSIONS OR COOKIES, just a simple page you enter the password you view it.
How can I do this ?
you should use 2 pages , one to enter the password, and the other to show the page...
the password page, will have a form
as POST
that points to page2.aspx
example of protected.aspx
:
<form action="page2.aspx" mehod="post">
Pasword: <input type="password" id="pwd" name="pwd" />
<input type="submit" value="Enter" />
</form>
and the Page_Load
event on page2.aspx
should be something like
if(Request["pwd"] == null || Request["pwd"] != "123") {
Response.Redirect("InvalidPassword.aspx");
}
Use two divs.
One which contains the main content and other containing a textbox and button.
<div id="MainDiv" runat="server" Visible="false">Main Content goes here. </div>
And the login div
<div id="LoginDiv" runat="server" Visible="true">
<asp:TextBox ID="PasswordTextBox" runat="server"></asp:TextBox>
<asp:Button ID="LoginButton" runat="server" Text="Button" OnClick="LoginButton_Click" /></div>
On login button click handler, check the password and toggle the visibility.
protected void LoginButton_Click(object sender, EventArgs e)
{
if(PasswordTextBox.Text=="Password")
{
MainDiv.Visible=true;
LoginDiv.Visible=false;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.