如何将密码登录名添加到ASP.NET页? [英] How do I add password login to an ASP.NET page?

查看:136
本文介绍了如何将密码登录名添加到ASP.NET页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个ASP.NET页面:site.com/foo/bar.aspx应该可以在世界范围内访问,而site.com/foo/baz.aspx我要用密码保护.我希望任何未经身份验证的用户看到用户名/密码页面,然后,一旦他们通过,我希望他们看到真实的东西.我正在寻找最简单的解决方案(看起来一直很好,直到它说要我搬东西),甚至以灵活性为代价.

I have two ASP.NET pages: site.com/foo/bar.aspx that should be world accessible and site.com/foo/baz.aspx that I want to password protect. I want any un-authenticated users to see a username/password page and then, once they pass that, I want them to see the real thing. I'm looking for the simplest possible solution (this looked good till it stated asking me to move things), even at the cost of flexibility.

我希望看到的是如果用户通过了身份验证就不会执行任何操作的控件,如果没有通过登录提示就将所有"其他控件替换为该控件.

What I'd love to see would be a control that does nothing if the user is authenticated and replaces "all" other controls with a login prompt if they aren't.

我是目前唯一拥有帐户的用户,因此我现在可以使用硬编码的密码列表(而且我或多或少受其困扰,因为我没有其他可放置的密码)

I'm currently the only user who will have an account so I can go with a hard coded password list for now (and I'm more or less stuck with that as I wouldn't have anywhere else to put it).

使用 Greg's 回答我可以对单个页面进行密码保护.使用 Joel Coehoorn的 链接我将其设置为进行表单身份验证.来自本页我正在使用如下所示的自定义登录逻辑:

Using Greg's answer I was able to make individual pages password protected. Using Joel Coehoorn's Link I set it up to do Forms Authentication. From this page I'm using a custom Login logic that looks like this:

    Login1.Authenticate += new AuthenticateEventHandler(Login1_Authenticate);

    ...

    void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        e.Authenticated = (Login1.UserName == "user" && 
                           Login1.Password == "password");
    }

所有这些似乎都可以正常工作. :)

All of that put together seems to work fine. :)

推荐答案

在这种情况下,最简单的事情可能是建立一个简单的登录页面预先建立的控件.

In that case, the easiest thing is probably forms authentication. You just hook everything up in your web.config file and build a simple login page using the pre-built controls.

这篇关于如何将密码登录名添加到ASP.NET页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆