简体   繁体   English

如何更改默认的MVC布局页面

[英]How to change default MVC layout page

I'm doing some development where I need to implemented a login form in MVC. 我正在做一些开发,需要在MVC中实现登录表单。 I have already created an MVC project in VS2013 which works OK. 我已经在VS2013中创建了一个MVC项目,可以正常工作。 When creating it, VS already include the forms and configuration to use the LogIn as well as the register views. 在创建它时,VS已经包括了使用LogIn以及注册视图的表单和配置。

the thing here is that that view use the layout.cshtml file as a master page. 这里的问题是该视图使用layout.cshtml文件作为母版页。 So, if I put the [Authorize] attribute to a method inside a controller what is happening when running the web site, is that it shows the LogIn page which is OK. 因此,如果我将[Authorize]属性赋予控制器内的方法,则在运行网站时会发生的情况是它显示了“登录”页面,该页面正常。 But using the layout.cshtml as the master page. 但是使用layout.cshtml作为母版页。

Is there a way to displayed the LogIn.cshtml page in the entiry window without using the layout.cshtml? 有没有一种方法可以在整个窗口中显示LogIn.cshtml页面而不使用layout.cshtml?

In the web.config I have: 在web.config中,我有:

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

But it doesn't work 但这不起作用

The layout applied to the Login.cshtml is being picked up, by convention, from _ViewStart.cshtml . 按照惯例,从_ViewStart.cshtml拾取应用于Login.cshtml的布局。

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

If you don't want to use this then add a 如果您不想使用此功能,请添加一个

@{
    Layout = null;
}

or 要么

@{
    Layout = "SomeOtherMaster.cshtml";
}

to the Login.cshtml page. 到Login.cshtml页面。

However by changing the Layout you're going to change out all the script and css references so you'll need to add in you own. 但是,通过更改布局,您将更改所有脚本和CSS引用,因此需要自己添加。 You should check in /Views/Shared/_Layout.cshtml to see what you'll be giving up. 您应该签入/Views/Shared/_Layout.cshtml以查看将要放弃的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM