首页 > 解决方案 > 在 Web 表单中的自定义配置文件提供程序上从用户获取和设置数据

问题描述

我一直在阅读一些教程,并创建了以下类,以便我可以获取用户数据并将其存储并在经过身份验证后随时在应用程序中访问它

using System;
using System.Configuration;
using System.Web;
using System.Web.Profile;

namespace FolhaRegisto.Models
{
    public class CustomProfileProvider : ProfileProvider
    {

        public override int DeleteInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new NotImplementedException();
        }
        public override int DeleteProfiles(string[] usernames)
        {
            throw new NotImplementedException();
        }
        public override int DeleteProfiles(ProfileInfoCollection profiles)
        {
            throw new NotImplementedException();
        }
        public override ProfileInfoCollection FindInactiveProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }
        public override ProfileInfoCollection FindProfilesByUserName(ProfileAuthenticationOption authenticationOption, string usernameToMatch, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }
        public override ProfileInfoCollection GetAllInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }
        public override ProfileInfoCollection GetAllProfiles(ProfileAuthenticationOption authenticationOption, int pageIndex, int pageSize, out int totalRecords)
        {
            throw new NotImplementedException();
        }
        public override int GetNumberOfInactiveProfiles(ProfileAuthenticationOption authenticationOption, DateTime userInactiveSinceDate)
        {
            throw new NotImplementedException();
        }
        public override string ApplicationName
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection)
        {
            throw new NotImplementedException();
        }
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection collection)
        {
            throw new NotImplementedException();
        }
    }
}

这是数据库,我想设置并获取 ProfileProvider 电子邮件,以便在用户通过身份验证时可以随时访问它。

CREATE TABLE hUtilizadores
(
    Id INT IDENTITY PRIMARY KEY,
    Username NVARCHAR(8) NOT NULL,
    Password NVARCHAR(100) NOT NULL,
    Acesso NVARCHAR(10) NOT NULL
)

CREATE TABLE hColaboradores
(
    IdUser INT UNIQUE NOT NULL,
    Nome NVARCHAR(100) NOT NULL,
    Email NVARCHAR(100) NOT NULL
)


ALTER TABLE hColaboradores
ADD CONSTRAINT FK_hColaboradores_hUtilizadores 
FOREIGN KEY (IdUser) 
REFERENCES hUtilizadores(Id)

在网络配置中我有这个

  <profile>
  <providers>
    <add
      name="CustomProfileProvider"
      type="FolhaRegisto.Models.CustomProfileProvider" 
      connectionStringName="GestaoRequisicoes" /> 
  </providers>
</profile>

因为关于 Web 表单的自定义配置文件提供程序的信息非常有限,所以我找不到任何明确的示例来说明如何在配置文件上获取数据和存储以及在哪里进行数据库调用我不知道我必须实现哪些功能以及在哪里我从数据库中获取数据

标签: c#asp.netsql-server

解决方案


推荐阅读