简体   繁体   English

ASP.NET成员资料

[英]ASP.NET Membership Profile

I want to send out an email to all users where their birthday is today 我想向今天过生日的所有用户发送一封电子邮件

I am using the built-in asp.net (3.5) membership. 我使用内置的asp.net(3.5)会员资格。 All users have a profile (stored in aspnet_Profile) which contains a date/time property called 'birthday'. 所有用户都有一个配置文件(存储在aspnet_Profile中),其中包含一个名为“birthday”的日期/时间属性。 I need to get a list of users email addresses from the 'aspnet_Membership' table where a users birthday is today, along with the users 'firstname' which is string property in the aspnet_Profile table. 我需要从今天用户生日的'aspnet_Membership'表中获取用户电子邮件地址列表,以及aspnet_Profile表中字符串属性的用户'firstname'。

I would like a list returned preferrably using C# LINQ. 我希望使用C#LINQ返回一个列表。

I am not sure how to access the birthday property in the profile table, based on the way it is stored in the db table ie name/value columns 我不知道如何访问配置文件表中的birthday属性,具体取决于它在db表中的存储方式,即名称/值列

I think you should consider changing to the much-improved table based provider: 我认为您应该考虑更改为经过大幅改进的基于表的提供程序:

http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx http://weblogs.asp.net/scottgu/archive/2006/01/10/435038.aspx

This allows you to separate your data into one value per table column in the standard SQL way. 这允许您以标准SQL方式将数据分成每个表列的一个值。 This performs petter than the standard provider and it solves your problem of querying the Profiles database. 这比标准提供程序执行得更少,它解决了查询“个人档案”数据库的问题。

It will take a small amount of work to convert the database, but on the code side, it is just a matter of configuring in a different provider and nothing else should change. 转换数据库需要花费少量工作,但在代码方面,只需要在不同的提供程序中进行配置,其他任何内容都不应该更改。 That is the beaurty of the provider pattern. 这是提供者模式的优点。

I don't use LINQ enough to give you a good answer, but the following may be the underlying SQL you need (This is how my SSMS generated it in the query designer): 我没有足够的LINQ给你一个很好的答案,但以下可能是你需要的基础SQL(这是我的SSMS在查询设计器中生成它的方式):

SELECT     aspnet_Profile.PropertyValuesString AS firstname, aspnet_Membership.Email
FROM         aspnet_Profile INNER JOIN
                      aspnet_Membership ON aspnet_Profile.UserId = aspnet_Membership.UserId INNER JOIN
                      aspnet_Profile AS aspnet_Profile_1 ON aspnet_Profile.UserId = aspnet_Profile_1.UserId
WHERE     (aspnet_Profile_1.PropertyNames LIKE N'birthday') AND (aspnet_Profile.PropertyNames LIKE N'firstname') AND (DATEADD(dd, 0, DATEDIFF(dd, 0, 
                      aspnet_Profile_1.PropertyValuesString)) = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE())))

The Profile mechanism parses the values out by splitting each name/value pair up, and then parsing them individually. Profile机制通过拆分每个名称/值对来解析值,然后单独解析它们。 You could write code to do that yourself. 您可以编写代码来自己完成。 Or you could follow @Daniel's approach and use the alternative provider, which makes life easier. 或者您可以遵循@Daniel的方法并使用替代提供程序,这使生活更轻松。 The out-of-the-box provider is a pain with the string concatenation. 开箱即用的提供程序是字符串连接的痛苦。

Is this code in the same app? 此代码是否在同一个应用程序中? You could just use the profile object to retrieve it, if you are talking C#... what context is this piece of code in? 如果您正在谈论C#,您可以使用配置文件对象来检索它...这段代码的上下文是什么? Batch service? 批量服务?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM