[英]Webmatrix.WebData.WebSecurity with MySql is not working. Throwing sql syntax error in WebSecurity.UserExists() check
[英]Using WebMatrix.WebData.WebSecurity in a WPF application
我有一個使用現成的WebMatrix安全性的MVC4 Internet項目。 提出了將WPF前端添加到同一應用程序的要求。 我已將模型移到單獨的DLL中,並開始在相同實體上構建WPF前端。
我唯一的問題是嘗試與現有的安全模型集成。 我已經在WPF項目的app.config中添加了一個system.web部分,如下所示:
<system.web>
<membership defaultProvider="SimpleMembershipProvider">
<providers>
<clear/>
<add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
</providers>
</membership>
</system.web>
現在,當我調用WebSecurity.Login("Username", "Password")
,出現以下錯誤:
在調用“ WebSecurity”類的任何其他方法之前,必須調用“ WebSecurity.InitializeDatabaseConnection”方法。 該調用應放在網站根目錄中的_AppStart.cshtml文件中。
我試過調用InitializeSimpleMembershipAttribute();
我的WPF應用程序啟動時MVC項目隨附的代碼,但對上述錯誤沒有影響。
我找不到任何在線示例,該怎么辦?
任何幫助,將不勝感激。
最后,我決定采用一種不同的方法,並使用WCF身份驗證服務在我的不同客戶端之間共享,如本文章演練:使用ASP.NET應用程序服務中所述 。
與嘗試使Web矩陣直接在WPF項目內部工作相比,這是一個更整潔的解決方案。
您需要做兩件事才能使它起作用
首先在Global.asax.cs中將其添加到Application_Start()的底部
var attr = new MixThread.Web.Filters.InitializeSimpleMembershipAttribute();
attr.OnActionExecuting(null);
其次,將此添加到您的Web.config
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
您應該能夠像這樣構建基於WCF的登錄名:
[AllowAnonymous]
public bool Login(string username, string password)
{
return WebMatrix.WebData.WebSecurity.Login(username, password);
}
您可能也需要將此添加到服務中。
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.