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

有帮助吗?

解决方案

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);
       }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top