Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8161975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:36:41+00:00 2026-06-06T18:36:41+00:00

I have this website (C#/ASP.NET) with a form where the user can register for

  • 0

I have this website (C#/ASP.NET) with a form where the user can register for an account (it is the default template of VS11) and after everything is filled in and the user clicks to register, it creates the account and logs in the user (which works great).

After this step I want to get the UserID which he was assigned, but it doesn’t work. I’ve put a breakpoint there to see the values of both “currentuserid” and “WebSecurity.CurrentUserId” but they only have a -1 value. Next step is the user gets redirected to the next page, and on that page these functions work. I thought I would be able to get the UserID as the user has already gotten logged in in the first line of the code I provided here.

So my question is, why doesn’t it work here? I am very noobish with this, so I am obviously missing something.

WebSecurity.Login(username, password);
int currentuserid = WebSecurity.CurrentUserId; // This doesn't work, only returns -1
<here I wish to update other tables but I need the user ID>
Response.Redirect("~/Welcome.cshtml");

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T18:36:43+00:00Added an answer on June 6, 2026 at 6:36 pm

    You should use WebSecurity.GetUserId(username)

    WebSecurity.Login(username, password);
    int currentuserid = WebSecurity.GetUserId(username);
    Response.Redirect("~/Welcome.cshtml");
    

    Take a look here: http://msdn.microsoft.com/en-us/library/webmatrix.webdata.websecurity.getuserid(v=vs.99)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website (ASP.NET MVC3) that runs on IIS 7. From this website,
I have this ASP.NET/SQLServer2005 website running on a production server (Win2003, QuadCore, 4GB). The
So I have this ASP.Net 2.0 website that uses functions contained within a JS
This is a simple website in ASP.NET with C# using VS 2010. I have
i have an asp.net website http://www.site.com . This web app is also running on
I have created a WebSite in ASP.Net(Not Mvc. i forgot the other name). After
I am using JQuery mobile in asp.net web form website. I have the following
I have an asp.net mvc register view. This is the first page. If someone
How can I implement following in ASP.NET MVC application: user opens intranet website user
I have an asp.net c# web application where a user can log in and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.