1

I have two different login pages in my MVC project, and depending on which URL is used to access the site the relevant login page needs to display (specific client requirements).

I am able to define which _layout is used based on the name of the login page in the _ViewStart:

if (Context.Request.Path.Contains("LoginG"))
    {
        Layout = "~/Views/Shared/_LayoutG.cshtml";
    }
    else { 
        Layout = "~/Views/Shared/_Layout.cshtml";
    }

But how can I set the initial view/landing page based on the URL?

Or can this be done in IIS?

Note: Both the login pages are actually identical other than the name, as the only reason I had to give it a different name was in order to apply the different layout in the _ViewStart!

Lyall
  • 1,367
  • 3
  • 17
  • 42
  • I would (and have in the past) implemented a [custom razor view engine](http://stackoverflow.com/questions/9838766/how-do-i-implement-a-custom-razorviewengine-to-find-views-in-non-standard-locati) to solve this issue – Liam Aug 22 '16 at 10:57

2 Answers2

1

In your Login ActionResult, get the returnUrl parameter which represents the url you are coming from (and will be redirected to after the successfull login) and return a different View according to its value, like this:

    public ActionResult Login(string returnUrl)
    {
        if (returnUrl == "url1")
        {
            return View("ViewName1");
        }

        return View("ViewName2");
    }
tocqueville
  • 5,270
  • 2
  • 40
  • 54
0

I solved my problem by removing the second version of the login page (leaving only the one login with two different versions of the layout) and choosing the layout page in the _ViewStart based on the domain the site is being accessed from:

if (Request.Url.AbsoluteUri.ToString().ToLower().Contains("xxxx"))
{
    Layout = "~/Views/Shared/_LayoutG.cshtml";
}  
else
{
    Layout = "~/Views/Shared/_Layout.cshtml";
}

This saves having to update the controller for returning different views, and works on all pages.

Lyall
  • 1,367
  • 3
  • 17
  • 42