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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:01:55+00:00 2026-05-13T21:01:55+00:00

I’m using MVC. I copied the login form from the login page and inserted

  • 0

I’m using MVC. I copied the login form from the login page and inserted into a new page (home controller, index view). I copied the code from the accounts controller into the index view. for some reason, i’m still not able to login. I’m not sure what’s wrong as it looks like I copied the necessary code exactly. When I use the form on the index page, I don’t get any validation errors, but it returns me back to the view and I’m not logged in.

You’ll notice that I changed this line to redirect to an Error page but I never get this far:

// If we got this far, something failed, redisplay form
            return RedirectToAction("Error", "Home");

I posted the code here: http://pastebin.com/RUj6ASvE

  • 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-13T21:01:56+00:00Added an answer on May 13, 2026 at 9:01 pm

    It’s because you are posting the from to the Index action whereas you should be posting it to the LogOn action, where your authentication logic is in.

    Try changing Html.BeginForm() to Html.BeginForm("LogOn", "HomeController") in your view.

    In the code you posted you were presenting the form from the HomeController‘s Index action. And posting it back to the same controller’s same action. But that action was not handling the authentication logic. That’s why nothing was happening and you weren’t logging in.

    In the default ASP.NET MVC 2 site, however, they are presenting the form from the AccountController‘s LogOn action :

    public ActionResult LogOn() {
        return View(); //returns the LogOn.aspx view
    }
    

    So when they use Html.BeginForm() in the view, it creates a form that will POST to the same controller’s same action. So they create another action with the name LogOn :

    [HttpPost]
    public ActionResult LogOn(LogOnModel model, string returnUrl) {
        //...
    }
    

    But this time they decorate that action with the HttpPost attribute. That means if a request hits the AccountController‘s LogOn action with the POST verb, that method above will be executed. But if the same action is requested with the GET verb (ie without a POST body) the other method will be executed.

    So basically, you could have done this in your HomeController :

    public ActionResult Index() {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";
        return View(); //returns the view which has the form
    }
    
    [HttpPost]
    public ActionResult Index(LogOnModel model, string returnUrl) {
        //handles the post
    }
    

    But your action (the one that was supposed to handle the authentication logic) was named differently. And that’s why we needed to explicitly set the controller and the action name in the Html.BeginForm("LogOn", "HomeController").

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

Sidebar

Related Questions

I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the

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.