如何更改默认 MVC 布局页面

How to change default MVC layout page

我正在进行一些开发,需要在 MVC 中实现登录表单。 我已经在 VS2013 中创建了一个工作正常的 MVC 项目。创建它时,VS 已经包含使用登录和注册视图的表单和配置。

这里的问题是该视图使用 layout.cshtml 文件作为母版页。因此,如果我将 [Authorize] 属性放入控制器中的方法,当 运行 网站时,它会显示登录页面,这是正常的。但是使用 layout.cshtml 作为母版页。

有没有办法在不使用 layout.cshtml 的情况下在整个 window 中显示 LogIn.cshtml 页面?

在 web.config 我有:

<authentication mode="Forms">
      <forms loginUrl="Account/Login" timeout="2880" />
    </authentication>

但是不行

按照惯例,应用到 Login.cshtml 的布局是从 _ViewStart.cshtml 中选取的。

@{
   Layout = "~/Views/Shared/_Layout.cshtml";
}

如果您不想使用它,请添加

@{
    Layout = null;
}

@{
    Layout = "SomeOtherMaster.cshtml";
}

进入Login.cshtml页面。

但是,通过更改布局,您将更改所有脚本和 css 引用,因此您需要添加自己的内容。你应该检查 /Views/Shared/_Layout.cshtml 看看你会放弃什么。