顯示具有 QA 標籤的文章。 顯示所有文章
顯示具有 QA 標籤的文章。 顯示所有文章

2012年11月7日 星期三

Q&A ASP.NET Dynamic Data 實體網站 -客製化

 

延續此文範例 Q&A ASP.NET Dynamic Data 實體網站

  • VS2012+ Windows 8
  • ASP.NET 4.5
  • for Lab2.3 自訂網頁範本

修改global.asax

image

加一個authors目錄

image

image

image

客製化,如加上字串

image

run

image

Q&A ASP.NET Dynamic Data 實體網站

 

  • VS2012+ Windows 8
  • ASP.NET 4.5
  • for Lab2.1 使用動態資料與語意標註

Visual Studio 2012 的ASP.NET Dynamic Data 實體網站範本,使用Entity Framework 5.0,因此要啟用Dynamic Data的語法有一點不同:

1.

image

Add ADO.NET Entity Data Model

image

image

image

image

image

image

 

修改global.asax,RegisterRoutes方法:

PS:這部分和VS2010最大不同的是DefaultModel.RegisterContext的寫法,需這樣寫

DefaultModel.RegisterContext(() =>
{
  return ((System.Data.Entity.Infrastructure.IObjectContextAdapter)new pubsEntities()).ObjectContext;
}, new ContextConfiguration() { ScaffoldAllTables = true });

ex:

image

執行網站測試

image

App_Code目錄,Add authors class:

[MetadataType(typeof(AuthorsMetadata))]
[DisplayName("作者")]
public partial class authors
{
  private class AuthorsMetadata
  {
    [DisplayName("姓氏")]
    public string au_lname { get; set; }
    [DisplayName("名字")]
    public string au_fname { get; set; }
  }
}

Run

image
image

2012年3月30日 星期五

Q & A : LocalDB IIS 權限問題

開發工具 : Visual Studio 11 Beta
作業系統 : Windows 7 Ultimate
IIS 7.5

因為blog有留言詢問有Local DB的網站,放在IIS上確無法執行的問題。米米想應該是權限問題吧,不過因為我用來測試的電腦上,居然沒有裝IIS (怎麼會有這種事??),所以沒有做測試,就請匿名的網友試試NTFS授權。
沒想到,回應是授權了也不work!!
這倒是一個有趣的問題,因此一早就把測試機器上的IIS 裝起來。
  • 使用Visual Studio 11 Beta 建一個Web Site在IIS
image
  • 加入LocalDB資料庫到網站
image
  • 新增Web Form
image
  • 將Table拉到網頁設計畫面
image
  • 一執行,果然出現了問題
image
  • 錯誤訊息如下,最後一行寫說”請看一下Event Log吧…”

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.
)

  • 打開Event Viewer看一看,有兩個明確的錯誤訊息。一個說Profile沒有load
image

  • 一個是拒絕存取
image
  • 針對第一個問題,Profile沒有load。開啟C:\Windows\System32\inetsrv\config目錄下的applicationHost.config檔案,找一下ProcessModel的設定,將以下兩項都設為true。
image
  • 針對第2個問題,權限的地方。檢查一下IIS目前的設定,TestWebSite網站建立在DefaultAppPool下。因為DefaultAppPool在IIS 7.5 使用的是ApplicationPoolIdentity來執行程式
image
  • 利用檔案總管,找到資料庫的Database1_log.ldf檔,授權ApplicationPoolIdentity帳號有Full Control 權限
image
image
  • 選不到帳號,要自己輸入字串:
image
  • 設Full Control
image

  • 按相同步驟,利用檔案總管,找到資料庫的Database1_log.mdf檔,授權ApplicationPoolIdentity帳號有Full Control 權限

  • 測試前,先IISRESET,讓組態確定套用。
image
  • 再執行網頁,問題就解決了。
image

2011年4月19日 星期二

Q&A 從WCF回傳ArrayList與自訂型別

收到李先生問題如下:
Q :
我的 WCF Service 需回傳 ArrayList,
若 ArrayList 只內含一些 string, 程式可 work,
但 ArrayList 若內含一些 Custom Class 就不 work,
請問老師問題出在那兒 ?
A:
善用DataContract與ServiceKnownType Attribute就可以囉~
例如Service Contract為:
[ServiceContract]
public interface IService {
    [OperationContract]
   [ServiceKnownType ( typeof ( CompositeType ) )]     ArrayList GetData ( );
}
[DataContract] public class CompositeType {
    bool boolValue = true;
    string stringValue = "Hello ";
    [DataMember]
    public bool BoolValue {
        get { return boolValue; }
        set { boolValue = value; }
    }
    [DataMember]
    public string StringValue {
        get { return stringValue; }
        set { stringValue = value; }
    }
}
服務:
public class Service : IService {
    public ArrayList GetData ( ) {
        ArrayList ar = new ArrayList ( );
        CompositeType c = new CompositeType ( );
        c.StringValue = "aaa";
        ar.Add ( c );
        return ar;
    }
}
產生Proxy 時要設
image
Client
ServiceReference1.ServiceClient c = new ServiceReference1.ServiceClient ( );
ArrayList ar = ( ArrayList ) c.GetData (  );
Console.WriteLine ( (( CompositeType ) ar [ 0 ]).StringValue.ToString() );

總網頁瀏覽量