简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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