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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:12:53+00:00 2026-05-27T07:12:53+00:00

I really don’t know what title should I use to describe my problem. To

  • 0

I really don’t know what title should I use to describe my problem. To simplify my problem. Here is my test. I create a mvc3 site from scratch. I then add area called “admin”. Inside admin, I have a controller named “Search” and has “Authorize” attribute decorated. I then changed my Global.ascx.cs route setting to append my controller namespace. Now I start my test.

Question 1

When I am accessing to http://localhost:xxx/Search page, it redirects me back to /Account/Logon page, it makes me confuse first, why it redirects me to logon page? it shouldn’t reach to Admin search controller at all as I understand. If I removed the Authorize attribute, it display the yellow screen said can’t find the view as I expected.

Question 2

If I add Authorize attribute with role, e.g. (Roles=”Admin”), then I try access to Search page again, no matter login succeed or not, I always get redirect back to logon page. Why it doesn’t give me the yellow screen, coz I am trying to request the search controller index view in the main site not the admin area’s one. quite confuse.

I am a newbie in MVC development, can someone give me a solution regarding to my problem?

Thanks

Global.ascx.cs

        public static void RegisterRoutes(RouteCollection routes) {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default", // Route name
            "{controller}/{action}/{id}", // URL with parameters
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },                      
            new string[]{"TestAreaRouting.Controllers"}
          );

        }
  • 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-27T07:12:54+00:00Added an answer on May 27, 2026 at 7:12 am

    You could constrain the default controller factory to look only inside the specified namespace for controllers in the RegisterRoutes method of Global.asax by setting the UseNamespaceFallback data token to false:

    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = UrlParameter.Optional },
            new string[] { "TestAreaRouting.Controllers" }
        ).DataTokens["UseNamespaceFallback"] = false;
    }
    

    If you don’t do this when you request /search the admin area route doesn’t match because the url doesn’t start with the Admin prefix.

    So it is the default route that matches. The default controller factory starts scanning the assembly for a class called SearchController that derives from Controller and since it finds one it instantiates it and uses it to serve the request. Obviously it doesn’t find a corresponding Index view because it looks in ~/Views/Search/Index.cshtml which obviously doesn’t exist. The actual view is located in the area.

    Now that we have constrained the controllers to their respective locations you could decorate them with the Authorize attribute and it should behave consistently.

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

Sidebar

Related Questions

I have a homework problem that I really don't know how to start. Here
I really don't know if it's a Netbeans issue but here's the problem: In
I really don't know how to describe it, but if you understood it and
I've just installed Resharper, and I really don't know how to use it correctly.
I really don't know how to title this question, but I need some help
I have this problem and really don't know how to solve this. I'm having
I really don't understand how to use SimpleXML in PHP. Here is an exemple
Ok guys I'm really at a dead end here, don't know what else to
I really don't know what my problem is lately, but Regex seems to be
I really don't know where to begin with this question, but the site I'm

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.