Pregunta

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#?

¿Fue útil?

Solución

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);
       }
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top