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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:31:19+00:00 2026-06-11T16:31:19+00:00

Visual Studio 2010 – MVC 3 I have an admin section of an asp.net

  • 0

Visual Studio 2010 – MVC 3

I have an admin section of an asp.net mvc application which I want to restrict access to. The application will not use accounts so I won’t be using an administrator role or user to authorize access for example.

I want the section to be accessible by the entry of a single password. There will be a number of actions in this section. I have set up an admin controller which redirects to a number of different views so basically any view which this controller controls needs to be restricted.

I would also like it so that the password only needs to be entered once for a session, so when the browser is closed and reopened the password would need to be re-entered.

How would I achieve this?

  • 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-11T16:31:20+00:00Added an answer on June 11, 2026 at 4:31 pm

    Assuming that you have a View folder called Protected (as your controller), and you have several Actions that points to several Views, I would do this:

    • decorate the controller/actions with an Action Filter, for example: [SimpleMembership]
    • on that action filter, just check the existence and the contents of a Session Variable
    • redirect to a SignIn if not the correct one

    in code:

    public class SimpleMembershipAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            //redirect if not authenticated
            if (filterContext.HttpContext.Session["myApp-Authentication"] == null ||
                filterContext.HttpContext.Session["myApp-Authentication"] != "123")
            {
                //use the current url for the redirect
                string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;
    
                //send them off to the login page
                string redirectUrl = string.Format("?ReturnUrl={0}", redirectOnSuccess);
                string loginUrl = "/Protected/SignIn" + redirectUrl;
                filterContext.HttpContext.Response.Redirect(loginUrl, true);
            }
        }
    }
    

    and your controller

    public class ProtectedController : Controller
    {
        [SimpleMembership]
        public ActionResult Index()
        {
            return View();
        }
    
        public ActionResult SignIn()
        {
            return View();
        }
        [HttpPost]
        public ActionResult SignIn(string pwd)
        {
            if (pwd == "123")
            {
                Session["myApp-Authentication"] = "123";
                return RedirectToAction("Index");
            }
            return View();
        }
    }
    

    if you want to decorate the entire controller, you need to move the SignIn methods outside as to reach there, you would need to be authenticated.


    Source code:

    You can download the simple MVC3 solution http://cl.ly/JN6B or fell free to view the code on GitHub.

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

Sidebar

Related Questions

Visual Studio 2010 Express, Windows Forms. Have made myself my first little application which
Background - Visual Studio 2010, C#, .Net Framework 4.0 application I have a web
Visual Studio 2010 RC -> Silverlight Application We have a library of images that
In Visual Studio 2010, I have a windows forms application frmMain.cs with a ComboBox.
Visual Studio 2010 / ASP.NET project / ASP.NET Development server I can run and
Visual Studio 2010, C#, ASP.NET & SQL Server 2008 are my main development tools,
Visual Studio 2010 - C# - MVC3 I am completely new to ASP.Net and
On Visual Studio 2010, when i create ASP.NET Web Site Project, every times i
Using Visual Studio 2010 and .NET framework 4.0 I have built a simple HelloWorld
Visual Studio 2010 MSSQL 2005 Windows Vista I am creating an ASP.NET website using

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.