I'm using the standard WebSecurity in web pages but I have a problem updating the username (e.g email). I have the following code which does update the db but does not update the "session cookie"??
if (action == "changeuser")
{
var newusername = Request.Form["changeuser"];
if (Validation.IsValid())
{
sql = "Select Email From UserProfile Where Email=@0";
var query = db.QuerySingle(sql, newusername);
if(query == null)
{
sql = "Update UserProfile Set Email=@0 Where UserId=@1";
db.Execute(sql, newusername, userId);
}
else
{
Response.Redirect("~/account/details/?action=userexists&changeuser=" + newusername);
}
}
}
As a result the logged in sesssion still thinks its current username is the old (pre updated) one.
Does anyone know how to resolve this or what session data I need to update as part of this process?
You'd have to log them out i guess, you need to end the current session, or it could be a cache issue, try refreshing several times, Cache is big issue for me with WebPages.
I have gone with the log out option, thanks for the replies guys.
At the moment the user has to "re-login" but if anyone can suggest a way that I can avoid having them login after a username change then I'd welcome that! :)
after your db.Execute statement. At least this works for me.
When push comes to shove, all WebSecurity does is call this method. The second parameter is whether or not to persist the auth cookie (i.e. "Remember Me"). That last bit if code simply queries the current ticket to get this value.
Member
31 Points
147 Posts
Web Matrix Security - Change username
Jun 06, 2013 08:24 AM|1jus|LINK
Hi all,
I'm using the standard WebSecurity in web pages but I have a problem updating the username (e.g email). I have the following code which does update the db but does not update the "session cookie"??
As a result the logged in sesssion still thinks its current username is the old (pre updated) one.
Does anyone know how to resolve this or what session data I need to update as part of this process?
Thanks,
Jus
Member
414 Points
518 Posts
Re: Web Matrix Security - Change username
Jun 06, 2013 10:13 AM|CriticalError|LINK
You'd have to log them out i guess, you need to end the current session, or it could be a cache issue, try refreshing several times, Cache is big issue for me with WebPages.
Contributor
4010 Points
1926 Posts
Re: Web Matrix Security - Change username
Jun 09, 2013 03:56 PM|Afzaal.Ahmad.Zeeshan|LINK
Listen, why not just update the column with usernames? And use that one as username? And let the email for that account work cool!
That would let you have a rest from that long code for Cookie and would also help you to let the user change the username!
That pretty more like it, as the user would have access to his account via both, Email and username! (If you want to let him in with username)
Member
445 Points
176 Posts
Re: Web Matrix Security - Change username
Jun 11, 2013 10:44 PM|mhcodner|LINK
You should log the user out then log them back in after they have changed their username. Change it to something like the following:
Member
31 Points
147 Posts
Re: Web Matrix Security - Change username
Jun 12, 2013 08:50 AM|1jus|LINK
I have gone with the log out option, thanks for the replies guys.
At the moment the user has to "re-login" but if anyone can suggest a way that I can avoid having them login after a username change then I'd welcome that! :)
Cheers
None
0 Points
1 Post
Re: Web Matrix Security - Change username
Jun 23, 2013 01:30 AM|ptyork|LINK
A little late, but just add:
after your db.Execute statement. At least this works for me.
When push comes to shove, all WebSecurity does is call this method. The second parameter is whether or not to persist the auth cookie (i.e. "Remember Me"). That last bit if code simply queries the current ticket to get this value.
Hope this helps.
Member
31 Points
147 Posts
Re: Web Matrix Security - Change username
Jul 07, 2013 12:13 PM|1jus|LINK
Thanks ptyork :)
Member
31 Points
147 Posts
Re: Web Matrix Security - Change username
Jul 07, 2013 12:13 PM|1jus|LINK
Thanks ptyork :)