【问题标题】:Using Forms Authentication without .Net providers在没有 .Net 提供程序的情况下使用表单身份验证
【发布时间】:2010-01-16 15:34:49
【问题描述】:

我想使用我在 web.config 中定义的用户名和密码使用表单身份验证来保护我网站的一部分。当我尝试登录时,我收到以下消息。

Server Error in '/' Application.

Could not find stored procedure 'dbo.aspnet_CheckSchemaVersion'.

我猜这是因为它试图使用由 LocalSqlServer 连接字符串定义的成员资格表。 我不想使用会员功能,如何配置我的网络应用程序来做到这一点?

我需要自己为内置的登录控件编写身份验证函数吗?

【问题讨论】:

标签: asp.net forms-authentication


【解决方案1】:

问题不在于您的配置文件,而在于登录控件。

登录控件使用在 machine.config 中定义的默认成员资格提供程序。 (它是一个指向 SQL Express 数据库的 SqlMembershipProvider)。

您根本不想使用默认的 Membership Provider。只需创建您自己的登录页面并使用以下服务器端逻辑来验证凭据并将用户登录到站点:

    if( Page.IsValid )
        if (FormsAuthentication.Authenticate(txtName.Text,txtPassword.Text)) 
            FormsAuthentication.RedirectFromLoginPage(txtName.Text, false);
        else
            lblMsg1.Text = "Wrong name or password. Please try again.";

【讨论】:

    【解决方案2】:

    试试这个:

    <authentication mode="Forms">
      <forms loginUrl="Login.aspx">
        <credentials>
          <user name="Joe" password="Smith" />
        </credentials>
      </forms>
    </authentication>
    

    【讨论】:

    • 我已经知道这个和这个设置了。即使我按照您描述的方式定义了配置,我的应用程序仍在尝试访问 SQL。
    • 您在 .config 中的会员条目怎么样?
    • 我的 web.config 中没有定义会员条目
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-03
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    相关资源
    最近更新 更多