簡體   English   中英

我可以在ASP.NET應用程序中將.cshtml文件用作LoginURL嗎?

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

當我的表單身份驗證LoginURL是.asp頁時,我的ASP.NET應用程序可以正常工作。 但是,我的應用程序的其余部分在Razor中,並且我無法獲得與其他頁面匹配的布局。 我嘗試用CSHTML頁面login.cshtml替換它,但在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..

對於我在Visual Studio中打開的每個.CSHTML頁面,該錯誤都會出現一次。

這是我的web.config中的Configuration / AppSettings值:

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

刪除網頁密鑰不能解決問題。

請注意,我正在使用MVC 3。

我正在嘗試做的事情甚至有可能嗎?如果可以,我該如何解決這個問題?

好像您只需要在項目中引用“ ASP.NET Web頁面”(如果我正確閱讀此博客文章)一樣,就可以將.cshtml文件用作常規頁面。

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

這為您提供了一個開始,但是它說安裝webmatrix(argh!)。

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

如果您安裝了nuget,則似乎確實有一個nuget軟件包。

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

不過不確定是否可以在mvc3中使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM