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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:52:12+00:00 2026-05-30T12:52:12+00:00

public ActionResult LogOn(string returnUrl) { if (Request.IsAuthenticated) { return RedirectToAction(string.Empty, home); } else {

  • 0
public ActionResult LogOn(string returnUrl)
        {
            if (Request.IsAuthenticated)
            {
                return RedirectToAction(string.Empty, "home");
            }
            else
            {
                if (!string.IsNullOrWhiteSpace(returnUrl))
                {
               //http://localhost:666/en-us/account/logon?returnurl=%2fen-us%2fadminka
                     //..............
                }
                return View();

            }
        }

        [HttpPost]
        public ActionResult LogOn(LogOnViewModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (....)
                {
                    //..............
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        return Redirect(returnUrl);
                    return RedirectToAction(string.Empty, "home");

                }
                else
                {
                    //..............
                }
            }

            return View(model);
        }

In HttpPost LogOn returnUrl is always equals null, even if it was not null in HttpGet LogOn.

Why? How do I fix it?

  • 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-30T12:52:13+00:00Added an answer on May 30, 2026 at 12:52 pm

    You need the returnUrl to be posted with the form post.

    Probably the cleanest solution is to add returnUrl as a property to the LogOnViewModel:

        public class LogOnViewModel
    {
        public string UserName { get; set; }
        public string Password { get; set; }
        public string ReturnUrl { get; set; }
    }
    

    Your get method would set that value:

    [HttpGet]
    public ActionResult LogOn(string returnUrl)
        {
           // code for already authenticated case left out for demo
                var model = new LogOnViewModel { ReturnUrl = returnUrl };
                return View(model);
    
            }
        }
    

    In your form, you would persist that value as a hidden field:

    @using (Html.BeginForm())
    {
        @Html.HiddenFor(model => model.ReturnUrl)
    
        // rest of form code left out for demo purposes
    }
    

    Your post method would then have access to that value:

        [HttpPost]
        public ActionResult LogOn(LogOnViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (....)
                {   string returnUrl = model.ReturnUrl;
    
                    //..............
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
                        && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                        return Redirect(returnUrl);
                    return RedirectToAction(string.Empty, "home");
    
                }
                else
                {
                    //..............
                }
            }
    
            return View(model);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public ActionResult Edit(string param) { } http://localhost/Edit/5,someothervalue,etc How can i reach 'param' from a
[AcceptVerbs(HttpVerbs.Post)] public ActionResult Upload(Photo photo) { foreach (string file in Request.Files) { var path
The controller is: public class HomeController : Controller { public ActionResult LogOn() { return
i have 2 actions public ActionResult FilesAdd(int id) { FillParentMenuDDL(id); return View(); } [HttpPost]
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have this in HomeController : public ActionResult Details(string id) { var customer =
I have the following code: public ActionResult SomeAction() { return new JsonpResult { Data
I have the following controller: public ActionResult Search(string Name, int? Friend, int? Page) It
ASP.NET MVC 2.0, here's my auth code: [AcceptVerbs(HttpVerbs.Post)] public ActionResult Login(string username, string password,
I have this url in my login page: http://localhost:5550/login?ReturnUrl=/forum/456 I have this controller: [HttpPost]

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.