0

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?

2

3 Answers 3

3

You could use authorization and location settings in web.config.

2

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).

1
  • This assumes they are on windows computers, and are internal network users. Jan 17, 2013 at 11:27
0

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 }
        }
4
  • Configuring IIS is far quicker than code changes. He'd have to enter this code, compile and redeploy in most circumstances.
    – Lloyd
    Jan 17, 2013 at 11:25
  • He asked for a quick way, this is a quick way. Configuring IIS will still recompile the website. Your ways also assume windows login is available.. Jan 17, 2013 at 11:26
  • Configuring IIS will NOT recompile the website. It might recycle the website though (not the same). Although you are correct, I am assuming it's Windows.
    – Lloyd
    Jan 17, 2013 at 11:28
  • Sorry yes, though it will still kick off any current people using and any data they are entering so same effect. Jan 17, 2013 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.