Question

When I browse to Facebook page without login, the page appears inviting me to create an account or login to Facebook. When I'm logged in, the same url shows another page.

What is the name of this technique? Can I do the same using C#?

Was it helpful?

Solution

The MVC routing engine points an URL to an action method rather than a html page. So in this actionmethod you can choose which html views will be returned depending on some coding conditions.

I'm not saying this is the approach they use, but this is an approach you could use.

So in ASP.NET MVC you could achieve this by using something like:

public ActionResult ViewProfile(string userToView)
{
       var model = new MyModel();

       //all the logic to fill the model

       if(CurrentUser.IsLoggedIn)
       {
            return View("ViewProfile", model);
       }
       else
       {
            return View("ViewProfileNotLoggedIn", model);
       }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top