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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:29:24+00:00 2026-05-25T13:29:24+00:00

I am trying to adapt the AccountController class so that it uses my own

  • 0

I am trying to adapt the AccountController class so that it uses my own backend database. In order to do this completely I need to send a string to the _Layout.cshtml to be checked. How is this possible?

I have tried with ViewData but this requires the Controller to correspond to the view attached e.g. AccountController to View/Account/LogOn.cshtml will work.

I believe that ViewBag works in the same way as I am getting a null reference when I try to access it in the _Layout.cshtml.

At the moment my code is a bit damaged due to trying to fix the problem but here is what I have. Hopefully it will help to explain better.

AccountController/[HTTP-POST] LogOn

...
if (user.GetRole(model.UserName).Equals("Admin"))
{
     ViewBag.Role = "Admin";
}
...

_Layout.cshtml

@if (Request.IsAuthenticated && ViewBag.Role.Equals("Admin"))
{
   ...
}

I no longer think this can be done with ViewBag or ViewData (Due to comments). Any solution would be welcome.

Thank you in advance – Ankou

  • 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-05-25T13:29:25+00:00Added an answer on May 25, 2026 at 1:29 pm

    Change your code to

    if (user.GetRole(model.UserName).Equals("Admin"))
    {
        ViewBag.Role = "Admin";
    }
    else{
        ViewBag.Role = "";
    }
    

    You will get an error of ViewBag.Role does not exist. So it must always be set.

    Edits

    From your comments, I think you might be best creating a Child Action which has it’s own controller and does the work for you.

    @Html.RenderAction("LogonDisplay");
    

    This will check the Roles, set the ViewBag values, and then display as needed.

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

Sidebar

Related Questions

Im trying to adapt some code that I have found online that uses this
I'm trying to adapt some code from a simple app that uses Raphael to
I'm trying to adapt this answer How do I tokenize a string in C++?
I'm looking at a cursor control class that I'm trying to adapt for my
I'm trying to adapt this DES encrypting example to AES, so I made the
So I'm trying to adapt this Dropdown menu on Joomla the styles work great
I'm trying to adapt a VBscript that runs the QWINSTA command against a text
I am trying to adapt the underlying structure of plotting code (matplotlib) that is
I'm trying to adapt this python code I found for connecting to the Dropbox
I'm trying to adapt the answers for filling a ListBoxFor that has preselected values

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.