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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:13:27+00:00 2026-05-29T15:13:27+00:00

Earlier I had similar issue. I have created asp mvc default template project and

  • 0

Earlier I had similar issue.
I have created asp mvc default template project and set authorization attribute on home controller.
When I run app url is:

http://localhost:48403/Account/LogOn?ReturnUrl=%2f

what I try to get is just http://localhost:48403 when user is no authenticated but I just have no luck with reouting setup 🙁
I have tried to put this in global.asax but no luck:

routes.MapRoute("Login", "",
                 new { controller = "Account", action = "LogOn" }
             );

This is my whole global.asax

routes.MapRoute("About", "About",
                 new { controller = "Home", action = "About" }
             );

            routes.MapRoute("Login", "",
                 new { controller = "Account", action = "LogOn" }
             );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
            );
  • 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-29T15:13:28+00:00Added an answer on May 29, 2026 at 3:13 pm

    You could write a custom Authorize attribute which instead if redirecting will directly render the LogOn view:

    public class MyAuthorizeAttribute : AuthorizeAttribute
    {
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            var viewResult = new ViewResult
            {
                ViewName = "~/Views/Account/LogOn.cshtml"
            };
            filterContext.Result = viewResult;
        }
    }
    

    then decorate your HomeController with it:

    [MyAuthorize]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
    }
    

    then your AccountController does no longer need to worry about ReturnUrls:

    public class AccountController : Controller
    {
        [HttpPost]
        public ActionResult LogOn(LogOnModel model)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    // TODO: obviously here instead of hardcoding the country and the city
                    // you might want to retrieve them from your backend given the username
                    return RedirectToAction("Index", "Home", new { country = "uk", city = "london" });
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }
    
            return View(model);
        }
    
        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index", "Home");
        }
    }
    

    and finally you will need to modify the action of the form in ~/Views/Account/LogOn.cshtml to point to the correct controller:

    @using (Html.BeginForm("LogOn", "Account")) {
        ...
    }
    

    You could leave your routes by default:

    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 }
        );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model with a CharField that earlier had unique set to True,
I had posted one question earlier jQuery inconsistency in setting readonly attribute in IE-8
I am concreting a question I had earlier. I have two classes in C++
This is a better understanding of a question I had earlier. I have the
I am going to handle XML files for a project. I had earlier decided
I had similar problem few days earlier but now is more complicated. I am
I had posted a similar question earlier - a slightly different requirement here. I
In my project, where I'm the lead developer, we earlier had a network configuration
I created a page in ASP that loads dynamic content with code similar to
I have tried posting this earlier and had to delete it because the code

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.