난 단지 사용자가 로그인 후 표시됩니다 내 페이지의 왼쪽에 메뉴 탐색을 설정하고 싶습니다.인증 및 탐색 모음
내가 MVC4 이것을 달성 할 수있는 방법을 모른다 내 index.cshtml 파일의 WebSecurity 클래스와 Razor. 비 로그인 사용자에 대한
_Layout.cshtml 및
_memberLayout.cshtml에 대한 : 당신이 윈도우 폼 인증을 사용하는 경우
난 단지 사용자가 로그인 후 표시됩니다 내 페이지의 왼쪽에 메뉴 탐색을 설정하고 싶습니다.인증 및 탐색 모음
내가 MVC4 이것을 달성 할 수있는 방법을 모른다 내 index.cshtml 파일의 WebSecurity 클래스와 Razor. 비 로그인 사용자에 대한
_Layout.cshtml 및
_memberLayout.cshtml에 대한 : 당신이 윈도우 폼 인증을 사용하는 경우
에서 살펴 로그인 사용자. 는 _memberLayout에 멤버 메뉴를 넣어.
/홈/색인 컨트롤러 :
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
return RedirectToAction("Index", "Member");
}
return View();
}
/회원/인덱스 컨트롤러 : 회원 폴더에
[Authorize]
public ActionResult Index()
{
return View();
}
Index.cshtml :
@{
ViewBag.Title = "Member Area";
Layout = "~/Views/Shared/_memberLayout.cshtml";
}
<div>
... your member html code
</div>
2 레이아웃을 사용하려고 User.Identity.IsAuthenticated
를 사용하여 두 개의 레이아웃 페이지을
,당신은 두 가지 옵션이 있습니다 _ViewStart.cshtml
변경
년 :먼저을 16,
Layout = "~/Views/Shared/_Layout.cshtml";
으로
if (Request.IsAuthenticated)
{
Layout = "~/Views/Shared/_MemberLayout.cshtml";
}
else
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
또는 : 모든보기의 시작 부분에서는 다음을 수행하십시오
@{
ViewBag.Title = "Home Page";
if (Request.IsAuthenticated)
{
Layout = "~/Views/Shared/_MemberLayout.cshtml";
}
}