简体   繁体   中英

Can I use a .cshtml file as the LoginURL in an ASP.NET app?

My ASP.NET application works fine when my Forms Authentication LoginURL is an .asp page. However, the rest of my app is in Razor, and I can't get the layout to match the other pages. I tried replacing it with a CSHTML page, login.cshtml, but I get this error in Visual Studio:

Warning 2   C:\Users\ddelgrande\Documents\Visual Studio 2010\Projects
\ABMCEditAndReports\ABMCEditAndReports\RazorLogin.cshtml:
ASP.NET runtime error: The pre-application start initialization method Start
on type System.Web.WebPages.Deployment.PreApplicationStartCode threw an
exception with the following error message:
Exception has been thrown by the target of an invocation..

The error appears once for every .CSHTML page I have open in Visual Studio.

Here are the Configuration/AppSettings values in my web.config:

<appSettings>
  <add key="webpages:Version" value="1.0.0.0"/>
  <add key="ClientValidationEnabled" value="true"/>
  <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>

Removing the webpages key does not fix the problem.

Note that I am using MVC 3.

Is what I am trying to do even possible, and if so, how do I get around this problem?

Looks like you just need "ASP.NET Web Pages" referenced in your project, if I read this blog post right, to use .cshtml files as regular pages.

http://blogs.msdn.com/b/davidebb/archive/2010/07/07/how-webmatrix-razor-asp-net-web-pages-and-mvc-fit-together.aspx

This gives you a start, but it says install webmatrix (argh!).

http://www.asp.net/web-pages/tutorials/introducing-aspnet-web-pages-2/getting-started

There does appear to be a nuget package for it if you have nuget installed.

http://www.nuget.org/packages/Microsoft.AspNet.WebPages

Not sure if that works with mvc3, though. Hrmmm.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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