參考這個博客
https://www.cnblogs.com/asks/p/4372783.html
在mvc中添加Forms驗證,沒用向導添加的,是因為那個和我原來的資料庫匹配不上。
修改Globl.asax
public class MvcApplication : System.Web.HttpApplication
{
public MvcApplication()
{
AuthorizeRequest += new EventHandler(MvcApplication_AuthorizeRequest);
}
void MvcApplication_AuthorizeRequest(object sender, EventArgs e)
{
IIdentity id = Context.User.Identity;//測驗的時候第一次進入會卡在這一句,提示空值。
if (id.IsAuthenticated)
{
var roles = new UserRepository().GetRoles(id.Name);
Context.User = new GenericPrincipal(id, roles);
}
}
//...
}
后來我用了if(Context.User!=null)跳過這句了,想和大佬請教一下,這句是不是本身就有問題,還是需要在其他地方修改一下能通過?
uj5u.com熱心網友回復:
將對應的應用程式池的托管管道模式改為經典試試uj5u.com熱心網友回復:
是用VS自帶的網頁服務器測驗的,沒部署到IIS轉載請註明出處,本文鏈接:https://www.uj5u.com/net/39813.html
標籤:ASP.NET
