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

  • Home
  • SEARCH
  • 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 8517499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:43:06+00:00 2026-06-11T05:43:06+00:00

Im converting a webforms app to mvc 4. The app does a fair amount

  • 0

Im converting a webforms app to mvc 4. The app does a fair amount of processing in the master page codebehind to do stuff such as determine what the user can or cant see based on their role, display a version at the bottom of the page from the assembly, etc. All server side.

I get that the processing isnt in a codebehind, but in a controller with the data sent to the view. But its not clear to me how this is done in the _Layout.cshtml

Thanks very much

  • 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-11T05:43:07+00:00Added an answer on June 11, 2026 at 5:43 am

    Something you might be able to do is to use a base controller and override the OnActionExecuting method and then use the ViewBag dynamic property to pass values to your _Layout.cshtml

    public abstract class BaseController : Controller
    {
       protected override void OnActionExecuting(ActionExecutingContext filterContext)
       {
          var user = filterContext.Controller.ControllerContext.RequestContext.HttpContext.User;
          // do whatever you need to do
          ViewBag.CanUserViewSomethingSecret = user.Identity.Name == "Kermit";
       }
    }
    

    You’d need to extend this base controller with application controllers

    public class HomeController : BaseController 
    {
        public ActionResult Index()
        {
            return View();
        }
    }
    

    Then in your _Layout.cshtml you can access the ViewBag property like so…

       @if(ViewBag.CanUserViewSomethingSecret != null && (bool) ViewBag.CanUserViewSomethingSecret == true) 
       {
           <p>Secret</p>
       }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm converting a legacy webforms app to MVC, working through it a page at
I'm converting an app from ASP.NET WebForms to WinForms. There is one asp.net page
I've been tasked with converting a one-page ASP.NET MVC 3 web app to ASP.NET
I'm converting a classic ASP page to ASP.NET MVC 2. I have a simple
I am coverting my app from webforms to mvc, at the moment i am
After converting an ASP.NET webform (v3.5) to use a master page, I started getting
I am just looking into converting WebForms to MVC: In .net MVC, what concepts
Currently converting an old asp.net web forms page into a asp.net mvc version, and
I am currently working on converting an existing webforms application to MVC and am
I am converting an ASP.Net web forms project to MVC3. The master page contains

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.