membership

Get UserId (int) in new MVC4 application

白昼怎懂夜的黑 提交于 2019-11-29 04:39:00
New MVC4 application created UserProfile table : UserId(int) | UserName(nvarchar) In controller : string currentUser = User.Identity.Name; // returns UserName var mu1 = Membership.GetUser(); // returns null var mu2 = Membership.GetUser(currentUser); // returns null as well I read a lot of threads and they all talk about getting Guid, which I don't even have in user and membership tables. Is there a way to get the UserId (int) of currently logged in User ? Make sure you add [InitializeSimpleMembership] to the top of your controller so that it initializes the simple membership via the file

How to check if element exists in array with jq

帅比萌擦擦* 提交于 2019-11-29 01:32:00
I have an array and I need to check if elements exists in that array or to get that element from the array using jq, fruit.json : { "fruit": [ "apple", "orange", "pomegranate", "apricot", "mango" ] } cat fruit.json | jq '.fruit .apple' does not work The semantics of 'contains' is not straightforward at all. In general, it would be better to use 'index' to test if an array has a specific value, e.g. .fruit | index( "orange" ) IN/1 If your jq has IN/1 then a better solution is to use it: .fruit as $f | "orange" | IN($f[]) If your jq has first/1 (as does jq 1.5), then here is a fast definition of

Membership Generate Password alphanumeric only password?

有些话、适合烂在心里 提交于 2019-11-28 23:40:29
问题 How can I use Membership.GeneratePassword to return a password that ONLY contains alpha or numeric characters? The default method will only guarantee a minimum and not a maximum number of non alphanumeric passwords. 回答1: string newPassword = Membership.GeneratePassword(15, 0); newPassword = Regex.Replace(newPassword, @"[^a-zA-Z0-9]", m => "9" ); This regular expression will replace all non alphanumeric characters with the numeric character 9. 回答2: A simple way to get an 8 character

How do I setup a Membership Provider in my existing database using ASP.NET MVC?

醉酒当歌 提交于 2019-11-28 19:12:35
For some reason, the idea of setting up Membership in ASP.NET MVC seems really confusing. Can anyone provide some clear steps to setup the requisite tables, controllers, classes, etc needed to have a working Membership provider? I know that the Demo that MVC ships with has an Accounts controller. However, should I be using this in my own project? What do I need to get my existing database ready if so? If not, how do I learn what I need to do to implement a membership provider? Check out this step by step blog on how to set up Membership provider in your asp.net mvc project. The sdk tool you

Implementing Custom MembershipUser

老子叫甜甜 提交于 2019-11-28 18:57:37
I am going round in circles and need some help in implementing a Custom MembershipUser so that I can add my own custom Properties to the MembershipUser. I have been following the example on this site: How to: Implement a Custom Membership User The problem I am having is in the constructor of CustomMembershipUser, I think. My CustomMembershipUser has these three additional Properties: firstName, middleName, lastName. public class CustomMembershipProvider : MembershipProvider { public override MembershipUser GetUser(string username, bool userIsOnline) { //.... Get data from database

ASP.Net Store User Data in Auth Cookie

限于喜欢 提交于 2019-11-28 18:40:56
I want to store some data like the user nickname and user ID (table primary key) in the user data section of the auth cookie. The reason I'm doing this is to retain this data when the browser is closed, without having the user relogin. Edit : Whoops! Realized I'd not explained myself well. I am not trying to reauthenticate a user based on their cookie. The user is already authenticated by ASP.Net's membership system - this part is fine. My problem is that if I want to show the user's nickname, for example, I have to fire off another SQL query, and then store it in the session. I figured it

Using ASP .NET Membership and Profile with MVC, how can I create a user and set it to HttpContext.Current.User?

不想你离开。 提交于 2019-11-28 16:34:55
I implemented a custom Profile object in code as described by Joel here: How to assign Profile values? I can't get it to work when I'm creating a new user, however. When I do this: Membership.CreateUser(userName, password); Roles.AddUserToRole(userName, "MyRole"); the user is created and added to a role in the database, but HttpContext.Current.User is still empty, and Membership.GetUser() returns null, so this (from Joel's code) doesn't work: static public AccountProfile CurrentUser { get { return (AccountProfile) (ProfileBase.Create(Membership.GetUser().UserName)); } } AccountProfile

How do you programmatically end a session in asp.net when Session.Abandon() doesn't work?

别来无恙 提交于 2019-11-28 09:52:55
Session.Abandon() doesn't seem to do anything. You would expect the Session_end event to fire when Session.Abandon() is called. This is most likely because your SessionMode is not InProc (the only one that can detect when a session ends). Quoted from MSDN : Session Events ASP.NET provides two events that help you manage user sessions. The Session_OnStart event is raised when a new session starts, and the Session_OnEnd event is raised when a session is abandoned or expires. Session events are specified in the Global.asax file for an ASP.NET application. The Session_OnEnd event is not supported

How to create user profiles with PHP and MySQL

可紊 提交于 2019-11-28 07:02:36
I need some help on creating a user profile system. I want it to be like Facebook or Myspace where it has only the username after the address, no question marks or anything, for example, www.mysite.com/username . I have all the register, logging scripts, etc. all done, but how do I go to profiles using the URL example above, "/username"? Chacha102 You would need to create a mod rewrite that took the first directory and passed it as a $_GET parameter. Try this: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.*)/$ index.php

How can I access UserId in ASP.NET Membership without using Membership.GetUser()?

﹥>﹥吖頭↗ 提交于 2019-11-28 06:28:20
How can I access UserId in ASP.NET Membership without using Membership.GetUser(username) in ASP.NET Web Application Project? Can UserId be included in Profile namespace next to UserName ( System.Web.Profile.ProfileBase )? Try this: MembershipUser CurrentUser = Membership.GetUser(User.Identity.Name); Response.Write("CurrentUser ID :: " + CurrentUser.ProviderUserKey); Is your reason for this to save a database call everytime you need the UserId? If so, when I'm using the ASP.NET MembershipProvider, I usually either do a custom provider that allows me to cache that call, or a utility method that