在新起一個ASP.NET MVC專案時,我們可以使用含有identity的範本,來作為會員登入的系統,但是往往我們前台使用identity時,後台就會選擇使用Form Authentication,或者選擇空專案,全部使用Form Authentication。
這次的練習,我是採用前後台都是使用同一套identity,藉由Role的不同來切分前後台的使用者。
閱讀全文〈ASP.NET MVC identity 使用Role來判斷前後台使用者〉
在新起一個ASP.NET MVC專案時,我們可以使用含有identity的範本,來作為會員登入的系統,但是往往我們前台使用identity時,後台就會選擇使用Form Authentication,或者選擇空專案,全部使用Form Authentication。
這次的練習,我是採用前後台都是使用同一套identity,藉由Role的不同來切分前後台的使用者。
閱讀全文〈ASP.NET MVC identity 使用Role來判斷前後台使用者〉
想要把Laravel PHP的程式部署到Azure上,原本覺得是一件很簡單的事情,因為前一陣子才在Azure上用WordPress建立我自己的部落格,前後也才花不到幾分鐘,一樣是用MySQL In App的方案(因為它便宜)。
台中的阿鴻來訊息說:phpMyAdmin連不上MySQL,我想說你這個肉腳,我來試試,再來教你,哈~哪來的自信阿….想不到竟然花了我約一週的時間,還好有Ming哥說他也被雷到,才找到一點蛛絲馬跡。
需安裝兩個套件
Microsoft.AspNet.WebHelpers
WebMatrix.WebData
Web.config 的<system.web> 需增加
<system.web> <authentication mode="Forms"> <forms loginUrl="~/Account/Login" timeout="2880" /> </authentication> <roleManager enabled="true" defaultProvider="SimpleRoleProvider"> <providers> <clear /> <add name="SimpleRoleProvider" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" /> </providers> </roleManager> <membership defaultProvider="SimpleMembershipProvider"> <providers> <clear /> <add name="SimpleMembershipProvider" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" /> </providers> </membership> </system.web>
當使用ASP.NET MVC在開發管理後台或系統時,關於權限的設定,第一步就是先將全站鎖住,再將Login那一頁用[AllowAnonymous] 開放。
Step01.在App_Start的檔案夾中找得 FilterConfig.cs,增加
filters.Add(new AuthorizeAttribute());
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
//增加這一行
filters.Add(new AuthorizeAttribute());
}
}
Step02.需安裝兩個nuget套件
Microsoft.Owin.Host.SystemWeb
Microsoft.Owin.Security.Cookies
Step03.新增一個OWIN Startup的類別,並命名為Startup.cs
public class Startup { public void Configuration(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { //作為辨識的的Cookie屬性 AuthenticationType = "ApplicationCookie", //如果無權限存取401 最後導頁的位置 LoginPath = new PathString("/Account/Login") }); } }