WebMatrix安裝&資料庫簡易連線&WordPress安裝

由 andy 發表於 五月 26, 2011 / 1 則評論

本文將大略用圖示示範WebMatrix如何安裝以及撰寫簡單的連線資料庫和Wordprss建立 希望可以讓有興趣的人先對WebMartix有些基本的認識。


何謂WebMatrix?

WebMatrix 是一個免費,簡易設定(輕量化)的網站開發工具,它提供了建立網站更簡單的方式。包含了IIS Express,ASP NET,SQL Server元件(嵌入資料庫).同時包含一些主流的開放式源碼的應用程式(套件)例如:WordPress,Joomla.。 這套工具開發時也可整合至VisualStudio和SQLServer。 你可以利用WebMatrix建立動態網頁.它可以根據使用者輸入的資訊來改變內容.例如取得資料庫資訊.甚至你可以使用ASPNET搭配Razor語法(前端)和C#或VB(後端).官方原文介紹:


WebMatrix is a free, lightweight set of web development tools that provides the easiest way to build websites. It includes IIS Express (a development web server), ASP.NET (a web framework), and SQL Server Compact (an embedded database). It also includes a simple tool that streamlines website development and makes it easy to start websites from popular open source apps. The skills and code you develop with WebMatrix transition seamlessly to Visual Studio and SQL Server. The web pages that you create using WebMatrix can be dynamic—that is, they can alter their content or style based on user input or on other information, such as database information. To program dynamic Web pages, you use ASP.NET with the Razor syntax and with the C# or Visual Basic programming languages.


安裝WebMatirx

使用微軟WebPlatform 安裝程式,這是一個免費的應用程式且容易安裝和執行相關網頁的設定.


Step1.


下載並安裝WebPlatform
http://www.microsoft.com/web/gallery/install.aspx?appid=webmatrix


若有其他套件或程式需要安裝


http://www.microsoft.com/web/downloads/platform.aspx?templang=zh-cht

 

 

 

 

 

 

Step 2 安裝ASP.NET Web Helpers Library 1.1

點選右下角「檔案」

 

點選系統管理

 

第一次進入時須建立密碼

 

輸入完密碼之後會跑出引導說明此時別急著按下方連結 先回到WebMatrix重新整理之後點開App_Data/Admin如下圖操作

 

 

點選引導頁面的連結或再次進入 輸入密碼後即可登入 搜尋 ASP.NET Web Helpers Library 1.1 安裝

 

Step 3 開始操作-開啟WebMatrix

 

到這一步時我們先選「依範本的站台」來了解一下整個WebMatrix的架構和基礎

 

建立站台選擇空白範例並為專案輸入名稱

 

 

如果您擅長使用VB語法就選擇vbhtml,如果是C#就選cshtml

 

可以試著輸入常用的時間函式 @DataTime.Now 也可以再加入@DataTime.Now.ToString("d") 這裡就跟C#一模一樣 新的Razor語法可以與C#或VB搭配使用,如其名剃刀式語法使用@去判斷是C#或者是HTML簡化本來的<%# %> 其中若要輸出可直接使用<div>等html標籤不需要再透過Response.Write.這個部分使得ASPNET MVC更方便在ASPMVC3有支援.

 

可以再試著更多應用

<form action=”” method=”post”> <input type=”text” name=”User” /> <input type=”submit” value=”送出”> </form> <div id=”MyBlock” runat=”server”> @if( Request["UserID"].IsEmpty() ){ <h3>你是訪客 現在時間@DateTime.Now</h3> }else{ <div>歡迎光臨 @Request["UserID"].ToString("d") </div> }</div>

 

建立資料庫與擷取資料 點選左下角資料庫後可建立資料庫,接著可以點選上方新增資料表或者對左邊樹狀目錄點選右鍵 建立資料表

 

 

 

範例程式碼

<!DOCTYPE html> @{ var Db = Database.Open("MyWeb"); var Query = Db.Query("Select * From WebMember"); var NewGridView = new WebGrid(Query); } <html lang="en"> <head> <meta charset="utf-8" /> <title>資料庫檢視會員</title> </head> <body> <form action="" method="post"> Name:<input type="text" name="name" id="name" /><br /> Addr:<input type="text" name="addr" id="addr" /><br /> <input type="submit"  /> </form> @if(!Request["name"].IsEmpty()&&!Request["addr"].IsEmpty()){ <div>Hello! @Request["name"].ToString() 你好啊~ 你是不是住在 @Request["addr"].ToString() </div> } <ul> @foreach(var Item in Query){ <li>@Item.id.@Item.name</li> } </ul> @NewGridView.GetHtml() </body> </html>

 

安裝OpenSource WordPress

 

 

 

 

 

 

關於作者

喜愛閱讀心理學與程式,資訊技術相關書籍,電影偏愛血淋淋,需要動腦的懸疑解謎,災難科幻類型.平時運動:游泳,慢跑等...最愛的一句話: Divide and Conquer! 無法掌握現在,如何談及未來!目前職業是程式設計師.

評論

  1. Ashely Marr 說: 2011/05/29

    Wow this is a great resource.. I’m enjoying it.. good article

發表評論

*