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 9056015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:05:31+00:00 2026-06-16T14:05:31+00:00

I am creating ASP.NET MVC web application. I have data model User: using System;

  • 0

I am creating ASP.NET MVC web application. I have data model User:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Knihovna.Models
{
    public class User
    {
        public int UserId { get; set; }
        public string Name { get; set; }
        public string Login { get; set; }
        public string Password { get; set; }
        public List<Book> Books { get; set; }
    }
}

and I need to create user registration and user login. Application needs to know If user is logged in.

Is there some best practises how to do it? Save logged in user in session?

  • 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-16T14:05:32+00:00Added an answer on June 16, 2026 at 2:05 pm

    I would use the ASP.NET membership and role provider model. If you would like to do it with your custom tables you can create a class that inherits from Membership Provider. There are a number of methods you can implement to support things like changing passwords, forgot password etc… but the one for logging in would be ValidateUser

    public sealed class MyMembershipProvider : MembershipProvider
    {
        public override bool ValidateUser(string username, string password)
        {
            bool isValid = false;
            // your authentication logic here
            var ticket = new FormsAuthenticationTicket(
                        1,
                        YOUR_USER_ID_HERE,
                        DateTime.Now,
                        DateTime.Now.AddMinutes(30),
                        false,
                        name,
                        FormsAuthentication.FormsCookiePath);
    
                    var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));
                    HttpContext.Current.Response.Cookies.Add(authCookie);
    
            return isValid;
        }
    }
    

    You will also need to create a role provider if you would like there to be different levels of users. To do so you will inherit from the RoleProvider class.

    public sealed class MyRoleProvider : RoleProvider
    {
       // Implement logic here
    }
    

    To authorize certain areas of your application you would use the Authorize attribute.

    public class MyController : Controller
    {
         [Authorize(Roles="Role1,Role2")]
         public ActionResult Index()
         {
             // Implement your code
         }
    }
    

    Finally there is some configuration in the web.config you have to do to get it to use your providers.

    <authentication mode="Forms">
      <forms loginUrl="~/Login" timeout="2880"/>
    </authentication>
    <membership defaultProvider="MyMembershipProvider" userIsOnlineTimeWindow="20">
      <providers>
        <clear/>
        <add name="MyMembershipProvider" type="Your.NameSpace.MyMembershipProvider" enablePasswordRetrieval="false" enablePasswordReset="false" requiresQuestionAndAnswer="false" writeExceptionsToEventLog="false"/>
      </providers>
    </membership>
    <roleManager enabled="true" defaultProvider="MyRoleProvider" cacheRolesInCookie="true">
      <providers>
        <clear/>
        <add name="MyRoleProvider" type="Your.NameSpace.MyRoleProvider"/>
      </providers>
    </roleManager>
    

    You can find more information about the memberhsip and role providers on MSDN

    • http://msdn.microsoft.com/en-us/library/f1kyba5e(v=vs.100).aspx
    • http://msdn.microsoft.com/en-us/library/8fw7xh74(v=vs.100).aspx
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a Web application using ASP.NET MVC, and I'm trying to use
I am creating a web application using ASP.NET MVC 4. I want to display
I'm creating a web application using ASP.NET MVC 4 and C#. I want all
I am creating a Web Application using ASP.NET MVC 3 and I would like
I am thinking about creating my new asp.net mvc web application compatible with native
I am creating a asp.net mvc application and loaded the data into jqgrid and
I have an ASP.NET MVC 2 application in which I am creating a custom
I have this web app that is running ASP .NET MVC 1.0 with LINQ
I'm creating an ASP.NET MVC application using F# on IIS 7. When I attempt
I'm creating a new MVC web application. I've never used MVC before (in asp.net).

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.