开发者

Membership : How to set userID to integer :S and not encrypted

CREATE TABLE [dbo].[aspnet_Membership](
 [Applicati开发者_运维知识库onId] [uniqueidentifier] NOT NULL,
 [UserId] [uniqueidentifier] NOT NULL,

Is there any easy ways to use and integer value as UserID (not this encrypted ...)

I really need integer :-/


You could easily write a custom membership provider that uses your database rather than the default ASP.NET one.

This is the main reason Microsoft went down the provider model, they have supplied an interface that you need to implement, and then the other tools (UI, access controls, etc) can all work with it.

A sample implementation can be found on MSDN:

How to: Sample Membership Provider Implementation

You'll notice that the ProviderUserKey on the MembershipUser is an Object, not a GUID, so you can use an Int, String, or whatever does it for you.

Another option would be to store this link in the users Profile, and then do the relevant lookups from there, but that wouldn't be as clean.

Edit to respond to comment

Well, it depends on where you want to do the work really. If you are happy to replicate the ASP.NET Membership stored procedures in your SQL database, you could get away with creating a class that (like the sample) inherits from MembershipProvider and only provide an override of the CreateUser method to create an integer based key, rather than a GUID based one.

Basically, the sample is showing you a complete implementation of a membership provider - all of those methods are implemented in much the same way in MembershipProvider, the override keyword on the methods and properties is telling the framework "Use my methods instead of the base class methods please".


Membership has GUID as UserId

MembershipUser myObject = Membership.GetUser();
string UserID = myObject.ProviderUserKey.ToString(); // it is the GUID as string

Of course, you can add other table UserId GUID, UserIdAsInteger and link it one-to-one with membership one, but you need some additional coding.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜