Reputation: 46222
I am using c# .NET Web Forms 4.0
I have a folder like the following that I need to password protect so anybody wanting to view the page needs to first enter a useridpassword (that we tell them) in order to view the page.
example:
www.abc.com/srlv/
so under srlv I have web pages that need to be password protected.
Is there a quick way to do this?
Upvotes: 0
Views: 485
Reputation: 10012
The quickest (not the best) way is:
Example Page Code. (Obviously include your usual web forms code... masterpages etc..
<html>
<body>
<div id="login_form" runat="server">
<asp:TextBox ID="username" runat="server"></asp:TextBox>
<asp:TextBox ID="password" TextMode="Password" runat="server"></asp:TextBox>
<asp:Button ID="Login" OnClick="Login_Click" runat="server" Text="Login" />
</div>
<div id="rest_of_site" runat="server" visible="false">
//rest of site...
</div>
Then on the Login_Click event:
protected void Login_Click(object sender, EventArgs e)
{
if ((username.Text == "Username") & (password.text == "Password"))
{
login_form.visible = false;
rest_of_site.visible = true;
}
else { //show some error }
}
Upvotes: 0
Reputation: 5757
You could use authorization and location settings in web.config.
Upvotes: 3
Reputation: 29668
Quickest way is to enable Windows Authentication for that folder, and turn off Anonymous access.
This does mean that you'll need a Windows account for them to log in with (either shared or individual).
Upvotes: 2