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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:49:09+00:00 2026-06-08T18:49:09+00:00

I learned I can redirect the user to a different page like this http://www.asp.net/web-forms/tutorials/security/membership/user-based-authorization-vb

  • 0

I learned I can redirect the user to a different page like this http://www.asp.net/web-forms/tutorials/security/membership/user-based-authorization-vb but I am wondering if there is a better way? Also, how can I just send an error message, instead of doing a redirect to a different view?

For instance, here is my code:

<Authorize(Roles:="Administrator")>
Public Class CompanyController

Could I add something like an error message to this if the user logs in but doesn’t have the right credentials? Could I set an error in the ViewBag.Error? Thanks for your help.

  • 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-08T18:49:11+00:00Added an answer on June 8, 2026 at 6:49 pm

    The point of the Authorize attribute is to prevent access to the controller action if the user is not allowed. It doesn’t execute the action at all and redirects to the LogOn action by default. The fact that the original action was not executed means that the view was not rendered.

    If you don’t want to get redirected to the LogOn action but create some custom view that will be rendered you could write a custom Authorize attribute and override the HandleUnauthorizedRequest method:

    Public Class MyAuthorizeAttribute
        Inherits AuthorizeAttribute
    
        Protected Overrides Sub HandleUnauthorizedRequest(filterContext As AuthorizationContext)
            Dim result = New ViewResult()
            result.ViewName = "Forbidden"
            result.ViewBag.ErrorMessage = "oops, you are not allowed"
            filterContext.Result = result
    End Sub
    End Class
    

    and then define the ~/Views/Shared/Forbidden.vbhtml view that will be rendered:

    <h3>@ViewBag.ErrorMessage</h3>
    

    and finally decorate your controller with this custom attribute:

    <MyAuthorize(Roles:="Administrator")>
    Public Class CompanyController
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I just learned from this question , .NET regexes can access individual matches
i've learned that you can register body onload like this: window.addEventListener('load', function, capture); //
Recently i learned that i can display images in a web page without referencing
IIS6, ASP.NET 2.0, No Forms Authentication I'm calling Response.Redirect(~/foo.aspx), but the default document (Default.aspx)
Through tutorials I had learned that you can define two variables in the same
During an ordeal yesterday, I learned that you can't pass this query to EXEC():
I've learned that Xor operation can be used to implement effective swap function. like
So I learned from this handy guide how to use .htaccess to redirect pretty
This question is specific to jqGrid. I learned that we can use .jqgrow item
I learned that Xcode can compile c code, that means can we write whole

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.