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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:53:59+00:00 2026-05-23T10:53:59+00:00

Been trying to put together an mvc login page that will redirect back to

  • 0

Been trying to put together an mvc login page that will redirect back to the original page that required authorization based on other stack overflow posts.

Redirect with

protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
  filterContext.Result = new RedirectToRouteResult(
                             new RouteValueDictionary 
                               {
                                   { "action", "login" },
                                   {"ReturnUrl", filterContext.HttpContext.Request.RawUrl},
                                   { "controller", "mycontroller" }
                               });
}

login page view has

@Html.Hidden("returnUrl", ViewContext.HttpContext.Request.Params["returnurl"])

located inside the form. I originally used ViewContext.HttpContext.Request.Url.PathAndQuery based on another forum post, but that included the entire url.

Inside controller I have

[HttpPost]
public ActionResult Login(MyModel model)
{
   if (loginisValid)
      return Redirect(model.ReturnUrl);
   else
      return View();
}

but that does nothing but return the orignal page even though it’s hitting the Redirect. I’ve also tried RedirectToAction and RedirectToRoute, but those give errors. I’m testing this on my index page which is at localhost/admin/mycontroller. So model.ReturnUrl currently contains “/admin/mycontroller”. What should I be changing to make this work?

  • 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-23T10:54:00+00:00Added an answer on May 23, 2026 at 10:54 am

    It turned out all this code was correct. However, I didn’t put

    [RequireHttps(Order=0)] 
    

    on top of my controller so it never stored cookies correctly and after redirecting back to my index page it was failing authorization again.

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

Sidebar

Related Questions

I have been trying to put together something that allows me to extract points
I'm trying to put together a batch file, that will ping a website, and
Okay, so here's the deal: I'm trying to put together a script that will
I've been looking at several other posts and trying to put together a way
I've been trying to put together a script which allows a user to select,
i'm trying to put together some Javascript form validation to check that all fields
I am trying to learn or put together the bits and pieces that I
I've been trying to put together a gui in MATLAB and have had great
So, I'm using boost 1.47.0 and I've been trying to put together a lexer.
I've been trying to put the pieces together on this for a while and

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.