开发者

Assign a post to a user in ASP.NET Membership

I'm writing a forum in ASP.NET. I have a table of posts. How can I assign a post to a user? If I had a normal User table, I'开发者_高级运维d just creating a new field in the post table "UserId" and creating an assocation in the Linq to Sql designer. But now? Should I include the aspnet_Users in the designer?

Thanks.


Including the table in your designer should not be necessary.

Simply define the UserId field in your Posts table as uniqueidentifier and supply the UserId when running your queries.

You can get the Guid (uniqueidentifier) UserId like this:

Guid UserId = (Guid) Membership.GetUser().ProviderUserKey;

There is absolutely no need to implement custom providers to facilitate this requirement.


Write your own ASP.NET Membership provider that uses your own database table and spare yourself the hassle of finding out how the MS lays out it's db tables.

I wrote a blog about that some years ago I think: http://www.tigraine.at/2008/07/08/custom-aspnet-membership-provider/

Hope this helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜