2012年12月24日 星期一

MVC music store補完 之「membership & Authorization 」

1.請到 project-->asp.net configuration,自然會開啟asp.net的設定網頁
2.在安全性的table中設定user & role,如果驗證狀態是windows,則要小小調整
參看下以附圖

   之後才能 create user,否則只能望role興嘆了.
3.設定好之後,該專案的最外層有個web.config會出現以下屬性:
  「 <authentication mode="Forms"/>」

4.依範例,在storeManager的class宣告前,加入「 [Authorize(Roles = "...")]」標註,以限制此控制器的存取權限

5..此時,你到專案的網站去執行,在輸入 「/storeManager」(欲進入storeManager controler)時,
 會指向「login.aspx」,而不是 Account/Login ,這時,元兇是出在於之前的「<authentication mode="Forms"/> 」 沒有設定完成,請依照以下修改:
   =============================
   <authentication mode="Forms">
      <forms loginUrl="~/Account/LogOn" timeout="2880" />
    </authentication>
   =============================
如此,再執行專案,再到/storeManager 控制器去時,就會看到登入頁面,登入後,自可使用之前的功能了
   **********************************************************
後記, 如果你沒好奇心,你就不能做programmer,  是的,你一定會想知道這些user資料放哪去了?
來,找到你的專案下的app_data資料夾(要用檔案總管去看,不是在vs2012方案總管去看)
就會看到新產生的mdf檔及log檔了.
又,因為IIS預設的資料庫連結是「 AspNetSqlProvider」,如果要修改的話
請參考:「how to re-config AspNetSqlProvider」--http://forums.asp.net/t/1059976.aspx/1

Visual Studio 2012的configuration website功能在哪?

 
參考連結: https://coderwall.com/p/13hlug

2012年12月22日 星期六

in MSSQL 如何把mdf檔轉成一般的資料庫?

為了要把mdf掛到我們的server,又不想要有一大掛的路徑字串,怎麼辦?
到查詢指令視窗,下以下指令
sp_attach_single_file_db @dbname='MvcMusicStore',@physname='D:\MVCMusicStore.mdf'

MSSQL ,要由windows 驗證改為sa 驗證方式的設定

1先以windwos驗證登入
2.在「安全性」->「登入」,找到sa的user,設定帳密

3. 切換到「狀態」,請把「連接到Database Engine」及「權限」都打開
4. 這還沒完,還要到server改一個屬性
改好了,這時,要重新啟動server,不是重新開機,就可以用sa登入了



MVC music store操作筆記--要加入欄位時

由於是用Code First,所以如果要在table上面加欄位時
請別直接加,而是先在model( entity class)中加入屬性
之後到「工具」-->「程式庫套件管理員」-->「Package Manager Console」
命令視窗中下指令:
Enable-Migrations -EnableAutomaticMigrations
Update-Database
 (如果是要刪除某個已在資料表中的欄位,會出現錯誤,這時要加上 「-Force」這個選項)

2012年12月20日 星期四

MVC Music Store Try & Error --CS0103 訊息 --'Scripts' 不存在於目前內容中

操作單元--「Edit form using Scaffolding」對Album進行增刪修的單元測試
在進入Edit功能時,會出現以下錯誤訊息:
=======================================================

編譯錯誤

描述: 資源編譯無法完成 (錯誤發生於服務要求)。請檢閱下列的特定錯誤詳細資料,並視情況修改您的原始程式碼。

編譯器錯誤訊息: CS0103: 名稱 'Scripts' 不存在於目前內容中

原始程式錯誤:


行 67: 
行 68: @section Scripts {
行 69:     @Scripts.Render("~/bundles/jqueryval")
行 70: }

原始程式檔: d:\MvcTestPrj\MvcTestPrj\Views\StoreManager\Edit.cshtml    行: 69
================================================

解決之道
1.用NuGet安裝「Web Optimization FrameWork」套件

2.參考(Reference)加上System.web.Optimization

3.在Web.conf的「namespace」屬性中,加入
「 <add namespace="System.Web.Optimization" /> 」這一項
 (如果不這樣,就要在各別的view中用 「@import System.Web.Optimization」)

4.在view目錄下的shared下的「_Layout.cshtml」中加入以下片段:
 ===========================================
 @if (IsSectionDefined("scripts"))
{
       @RenderSection("scripts", required: false)
}
===============================================
  (我是把他加在<script src...>....</script>之後)

2012.12.23:
雖然上述沒有出現compile的錯誤,但如果用firebug就知道根本還是找不到
「~/bundles/jqueryval」 ,
所以還是需要以下步驟
step 5.在App_start目錄中加入一個類別 BundleConfig
  內容如下
using System.Web.Optimization;
namespace MvcTestPrj.App_Start
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                                   "~/Scripts/jquery.unobtrusive*",
                                   "~/Scripts/jquery.validate*"));

        }
    }
}


step 6  到Global.aspx加入Boundle
 一樣還是要using System.Web.Optimization;
  =============================
      protected void Application_Start()
        {
            BundleConfig.RegisterBundles(BundleTable.Bundles);

                  ...
                 ...
 =========================================
  如此才算真的是功德圓滿了

2012年12月12日 星期三

讓win7資料夾中的文件隨意排列

儘管win8已經上市了,不過我手上的nb都還是灌win7的為主
(有的業者的公司還是用xp的,他們的系統還是用jdk1.4去寫的,.net 2.0還是「踢倒街」)
不過win7的資料夾有個很令人「強迫中獎」的自動排列 ,有人說這很好啊,
問題是以前在xp是習慣用性質去group某幾區的icon(ex:開發工具一區、DB一區,.net一區, java一區...),以便自己可以快速點選,被win7這麼一搞,天下大亂
 當然這不只是我有這樣的需求,很多人也是如此 ,如果你也有這樣的需要的話,那你今天來對地方了,請把以下的文字內容存成「.reg」檔
====以下是reg檔的內容=====================
Windows Registry Editor Version 5.00
;Disable Full Row Select feature in Windows 7
;Created by Ramesh Srinivasan
;http://hi.baidu.com/liuxilife
;Created on 19 Feb 2010
[-HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
"FullRowSelect"=dword:00000000
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell]
"KnownFolderDerivedFolderType"="{57807898-8C4F-4462-BB63-71042380B109}"
"SniffedFolderType"="Generic"
;Generic - Folder Template
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{5C4F28B5-F869-4E84-8E60-F11DB97C5CC7}]
"Rev"=dword:00000000
"FFlags"=dword:43000001
"Vid"="{137E7700-3573-11CF-AE69-08002B2E1262}"
"Mode"=dword:00000004
"LogicalViewMode"=dword:00000001
"IconSize"=dword:00000010
"ColInfo"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,fd,df,df,fd,10,\
00,00,00,00,00,00,00,00,00,00,00,04,00,00,00,18,00,00,00,30,f1,25,b7,ef,47,\
1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,10,01,00,00,30,f1,25,b7,ef,47,1a,\
10,a5,f1,02,60,8c,9e,eb,ac,0e,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,\
a5,f1,02,60,8c,9e,eb,ac,04,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,a5,\
f1,02,60,8c,9e,eb,ac,0c,00,00,00,50,00,00,00
"Sort"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,30,f1,\
25,b7,ef,47,1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,01,00,00,00
"GroupView"=dword:00000000
"GroupByKey:FMTID"="{00000000-0000-0000-0000-000000000000}"
"GroupByKey:PID"=dword:00000000
"GroupByDirection"=dword:00000001
;Documents - Folder Template
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{7d49d726-3c21-4f05-99aa-fdc2c9474656}]
"Rev"=dword:00000000
"Vid"="{137E7700-3573-11CF-AE69-08002B2E1262}"
"Mode"=dword:00000004
"LogicalViewMode"=dword:00000001
"IconSize"=dword:00000010
"ColInfo"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,fd,df,df,fd,10,\
00,00,00,00,00,00,00,00,00,00,00,04,00,00,00,18,00,00,00,30,f1,25,b7,ef,47,\
1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,10,01,00,00,30,f1,25,b7,ef,47,1a,\
10,a5,f1,02,60,8c,9e,eb,ac,0e,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,\
a5,f1,02,60,8c,9e,eb,ac,04,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,a5,\
f1,02,60,8c,9e,eb,ac,0c,00,00,00,50,00,00,00
"Sort"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,30,f1,\
25,b7,ef,47,1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,01,00,00,00
"GroupView"=dword:00000000
"GroupByKey:FMTID"="{00000000-0000-0000-0000-000000000000}"
"GroupByKey:PID"=dword:00000000
"GroupByDirection"=dword:00000001
"FFlags"=dword:43000001
;Music - Folder Template
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{94d6ddcc-4a68-4175-a374-bd584a510b78}]
"Rev"=dword:00000000
"Vid"="{137E7700-3573-11CF-AE69-08002B2E1262}"
"Mode"=dword:00000004
"LogicalViewMode"=dword:00000001
"IconSize"=dword:00000010
"ColInfo"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,fd,df,df,fd,10,\
00,00,00,00,00,00,00,00,00,00,00,04,00,00,00,18,00,00,00,30,f1,25,b7,ef,47,\
1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,10,01,00,00,30,f1,25,b7,ef,47,1a,\
10,a5,f1,02,60,8c,9e,eb,ac,0e,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,\
a5,f1,02,60,8c,9e,eb,ac,04,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,a5,\
f1,02,60,8c,9e,eb,ac,0c,00,00,00,50,00,00,00
"Sort"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,30,f1,\
25,b7,ef,47,1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,01,00,00,00
"GroupView"=dword:00000000
"GroupByKey:FMTID"="{00000000-0000-0000-0000-000000000000}"
"GroupByKey:PID"=dword:00000000
"GroupByDirection"=dword:00000001
"FFlags"=dword:43000001
;Pictures - Folder Template
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{b3690e58-e961-423b-b687-386ebfd83239}]
"Rev"=dword:00000000
"Vid"="{137E7700-3573-11CF-AE69-08002B2E1262}"
"Mode"=dword:00000004
"LogicalViewMode"=dword:00000001
"IconSize"=dword:00000010
"ColInfo"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,fd,df,df,fd,10,\
00,00,00,00,00,00,00,00,00,00,00,04,00,00,00,18,00,00,00,30,f1,25,b7,ef,47,\
1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,10,01,00,00,30,f1,25,b7,ef,47,1a,\
10,a5,f1,02,60,8c,9e,eb,ac,0e,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,\
a5,f1,02,60,8c,9e,eb,ac,04,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,a5,\
f1,02,60,8c,9e,eb,ac,0c,00,00,00,50,00,00,00
"Sort"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,30,f1,\
25,b7,ef,47,1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,01,00,00,00
"GroupView"=dword:00000000
"GroupByKey:FMTID"="{00000000-0000-0000-0000-000000000000}"
"GroupByKey:PID"=dword:00000000
"GroupByDirection"=dword:00000001
"FFlags"=dword:43000001
;Videos - Folder Template
[HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\Bags\AllFolders\Shell\{5fa96407-7e77-483c-ac93-691d05850de8}]
"Rev"=dword:00000000
"Vid"="{137E7700-3573-11CF-AE69-08002B2E1262}"
"Mode"=dword:00000004
"LogicalViewMode"=dword:00000001
"IconSize"=dword:00000010
"ColInfo"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,fd,df,df,fd,10,\
00,00,00,00,00,00,00,00,00,00,00,04,00,00,00,18,00,00,00,30,f1,25,b7,ef,47,\
1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,10,01,00,00,30,f1,25,b7,ef,47,1a,\
10,a5,f1,02,60,8c,9e,eb,ac,0e,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,\
a5,f1,02,60,8c,9e,eb,ac,04,00,00,00,78,00,00,00,30,f1,25,b7,ef,47,1a,10,a5,\
f1,02,60,8c,9e,eb,ac,0c,00,00,00,50,00,00,00
"Sort"=hex:00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,01,00,00,00,30,f1,\
25,b7,ef,47,1a,10,a5,f1,02,60,8c,9e,eb,ac,0a,00,00,00,01,00,00,00
"GroupView"=dword:00000000
"GroupByKey:FMTID"="{00000000-0000-0000-0000-000000000000}"
"GroupByKey:PID"=dword:00000000
"GroupByDirection"=dword:00000001
"FFlags"=dword:43000001
==================以上是reg檔的文字內容=============
存好了這個reg檔後,滑鼠點右鍵,選「合併」之後,要重開機哦
 之後再回到你要玩的資料內試看看吧
(我試過的,it works!!)