c# - ASP.NET MVC Identity Framework hangs on FindByEmail call in development, but not live version -
our website uses mvc , identity framework 2.0. on live site (fortunately) users can log in perfectly:
here's code makes work attached login action of account controller:
public async task<actionresult> login(vmaccountlogin model, string returnurl) { // if problems model, redisplay form if (!modelstate.isvalid) { return view(model); } // hangs on line var user = usermanager.findbyemail(model.email); // if user not found email, abort no clues if (user == null) when build project , copy dll live server, works perfectly. ...
on test version, hangs on line shown. after ten seconds debugging jumps dispose method. i've gone through web.config file line line check they're same. i've read many articles, don't think of them apply problem. here's usermanager call, way, works fine:
public applicationusermanager usermanager { { return _usermanager ?? httpcontext.getowincontext().getusermanager<applicationusermanager>(); } private set { _usermanager = value; } } if enable debugging of .net symbols, hangs on findbyemail method call. getusermanager call shows in immediate window:
?httpcontext.getowincontext().getusermanager<applicationusermanager>(); {wiseowl.applicationusermanager} claimsidentityfactory: {microsoft.aspnet.identity.claimsidentityfactory<wiseowl.models.applicationuser, string>} defaultaccountlockouttimespan: {00:05:00} emailservice: {wiseowl.emailservice} maxfailedaccessattemptsbeforelockout: 5 passwordhasher: {microsoft.aspnet.identity.passwordhasher} passwordvalidator: {microsoft.aspnet.identity.passwordvalidator} smsservice: {wiseowl.smsservice} store: {microsoft.aspnet.identity.entityframework.userstore<wiseowl.models.applicationuser>} supportsqueryableusers: true supportsuserclaim: true supportsuseremail: true supportsuserlockout: true supportsuserlogin: true supportsuserpassword: true supportsuserphonenumber: true supportsuserrole: true supportsusersecuritystamp: true supportsusertwofactor: true twofactorproviders: count = 2 userlockoutenabledbydefault: true usertokenprovider: {microsoft.aspnet.identity.owin.dataprotectortokenprovider<wiseowl.models.applicationuser>} uservalidator: {microsoft.aspnet.identity.uservalidator<wiseowl.models.applicationuser>} users: {system.data.entity.dbset<wiseowl.models.applicationuser>} _claimsfactory: {microsoft.aspnet.identity.claimsidentityfactory<wiseowl.models.applicationuser, string>} _defaultlockout: {00:05:00} _disposed: false _factors: count = 2 _passwordhasher: {microsoft.aspnet.identity.passwordhasher} _passwordvalidator: {microsoft.aspnet.identity.passwordvalidator} _uservalidator: {microsoft.aspnet.identity.uservalidator<wiseowl.models.applicationuser>} does have suggestions please?
so far hanging on test environment looks mixing of async , blocking calls can lead deadlocks. findbyemail extension method wraps async api call of usermanager.findbyemailasync.
the source code version found in usermanagerextensions.cs shows async call being executed synchronously.
/// <summary> /// find user email /// </summary> /// <param name="manager"></param> /// <param name="email"></param> /// <returns></returns> public static tuser findbyemail<tuser, tkey>(this usermanager<tuser, tkey> manager, string email) tkey : iequatable<tkey> tuser : class, iuser<tkey> { if (manager == null) { throw new argumentnullexception("manager"); } return asynchelper.runsync(() => manager.findbyemailasync(email)); } i believe causing deadlock (hang) when run in test environment. not explain why still works in live environment though.
i suggest making code async way through via findbyemailasync method intended. try avoid mixing async , blocking calls.
public async task<actionresult> login(vmaccountlogin model, string returnurl) { // if problems model, redisplay form if (!modelstate.isvalid) { return view(model); } // hangs on line var user = await usermanager.findbyemailasync(model.email); // if user not found email, abort no clues if (user == null) //...code removed brevity outside of suggest making sure test environment using correct connection string identity data store. hang may due timeout waits connect database.

Comments
Post a Comment