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

The Archive Base Latest Questions

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

I have an MVC application, which has two areas – Administrator, and User. What

  • 0

I have an MVC application, which has two areas – Administrator, and User. What I wanted to do, is on first login, the User will activate their account, agree to terms and conditions, etc. This application uses the asp membership api.

I have inserted an IF statement into the POST login action in the Account controller, however after debugging, it appears that this if statement is never executed. If someone could take a look at it I’d be very grateful. I have a feeling it could be something small I’m missing.

The login URL for the User is:

http://localhost:80/Account/LogOn?ReturnUrl=/User

The administrator URL is:

http://localhost:80/Account/LogOn?ReturnUrl=/Administrator

however both use the same login action in the account controller so hence the need to use an if statement to differentiate between the two.

Here is the code for the POST Logon action. The string returnUrl is “/User” not “User” which I discovered after debugging through the code.

 [HttpPost]
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (MembershipService.ValidateUser(model.UserName, model.Password))
                {
                    FormsService.SignIn(model.UserName, model.RememberMe);
                    if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        string url = returnUrl;

                        if (url == "/User")
                        {
                            ModelContainer ctn = new ModelContainer();

                            MyApp.Data.User p = ctn.Users.First(t => t.UserID == UserServices.CurrentUserId);

                            string status = p.AccountStatus;

                            if (status != "Active")
                            {
                                return RedirectToAction("contract", "Home");
                            }
                            else
                            {
                                return RedirectToAction("Index", "Home");
                            }
                        }
                        else
                            return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

It just seems to skip after the else here:

if (!String.IsNullOrEmpty(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        string url = returnUrl;

and jumps right down to the final RedirectToAction.

I’d be very grateful if anyone could spot anything. If more info is needed just shout!

  • 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-18T21:25:14+00:00Added an answer on May 18, 2026 at 9:25 pm

    This will not go further than the if case when returnUrl == "/User" or any other value

    if (!String.IsNullOrEmpty(returnUrl))
    {
        return Redirect(returnUrl);
    }
    

    If not is null or empty, and if returnUrl == "/User", this is true since "/User" is not null and it is not empty.

    and your second part will always be null or empty:

    string url = returnUrl;
    
    if (url == "/User")
    {
    

    so this will “appear” like something isn’t working.

    My suggestion would be to return the “true” case first in an if/ else for clarity:

    if (string.IsNullOrEmpty(returnUrl))
    {
        // do the default cases
    }
    else
    {
        // redirect to returnUrl
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have this application in ASP MVC 3. My database has two tables:
I have a MVC application which has a Controller that has a recursive method
I have an .Net MVC application which runs fine if I use the build
I have an ASP.NET MVC-application which I want deployable on both IIS6 and IIS7
I have an application, built using MVC, that produces a view which delivers summary
I have an ASP.NET MVC application, when a user clicks on the submit button
I have an ASP.Net MVC application with a model which is several layers deep
I am writing an ASP.Net MVC application. I have two entities - patients and
I have a wizard in my asp.net MVC application which is built upon this
I have an ASP.NET MVC 3 (Razor) Web Application, with a particular page which

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.