Spiga

如何讓 MOSS 支援 AJAX

如果要讓 MOSS 支援 AJAX,首先必須先下載 ASP.NET 2.0 AJAX Extensions 1.0 (按 這裡 下載),然後在 MOSS 伺服器上安裝它,安裝完畢之後,接下來要修改 MOSS 網站的 web.config 檔,一般是位於 c:\inetpub\wwwroot\wss\VirtualDirectories\80 資料夾下,也就是當初在建立應用程式時所設定的路徑,如下圖最下面的路徑:
##ReadMore##

1. 在 <configSections> 元素下加入 <sectionGroup> 子元素如下:

<configSections>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
      <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
        <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
          <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="Everywhere" />
          <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
          <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication" />
        </sectionGroup>
      </sectionGroup>
    </sectionGroup>
</configSections>

2. 在 <system.web>/<pages> 元素下加入 <controls> 子元素如下:

<pages>
      <controls>
        <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      </controls>
</pages>

 

3. 在 <compilation> 元素下加入 <assemblies> 子元素如下:

<assemblies>
       <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</assemblies>

 

4. 在 <httpHandlers> 區段最後面加入以下 handlers 的註冊:

<httpHandlers>
      <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
</httpHandlers>

 

5. 在 <httpModules> 區段中加入以下模組:

<httpModules>
      <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>

 

6. 在 <SharePoint>/<SafeControls> 區段中加入以下安全控制項註冊:

<SafeControls>
      <SafeControl Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TypeName="*" Safe="True" />
</SafeControls>

 

7. 在 web.config 最後面的 </configuration> 這一行之前加上:

<system.web.extensions>
    <scripting>
      <webServices>
      <!-- Uncomment this line to enable the authentication service. Include requireSSL="true" if appropriate. -->
      <!--
        <authenticationService enabled="true" requireSSL = "true|false"/>
      -->
      <!-- Uncomment these lines to enable the profile service. To allow profile properties to be retrieved and modified in ASP.NET AJAX applications, you need to add each property name to the readAccessProperties and writeAccessProperties attributes. -->
      <!--
      <profileService enabled="true"
                      readAccessProperties="propertyname1,propertyname2"
                      writeAccessProperties="propertyname1,propertyname2" />
      -->
      </webServices>
      <!--
      <scriptResourceHandler enableCompression="true" enableCaching="true" />
      -->
    </scripting>
  </system.web.extensions>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <add name="ScriptModule" preCondition="integratedMode" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    </modules>
    <handlers>
      <remove name="WebServiceHandlerFactory-Integrated" />
      <add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode"
           type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
      <add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </handlers>
</system.webServer>

 

8. 在主版頁面中加入 ScriptManager 控制項,主版面頁檔位於 \\[你網站網址]\_catalogs\masterpage 資料夾之下,預設檔名是 default.master,在 <WebPartPages:SPWebPartManager> 控制項下一行加入 <asp:ScriptManager> 控制項如下:

<WebPartPages:SPWebPartManager id="m" runat="Server"/>

<asp:ScriptManager runat="server" ID="ScriptManager1"></asp:ScriptManager>

 

9. 接下來你就可以在頁面中或 WebPart 中使用 UpdatePanel 這一類的 AJAX 控制項了。

 

參考資料: Integrating ASP.NET AJAX with SharePoint

如何在 MOSS 網頁中使用 C# 程式碼

在使用 SharePoint Designer 2007 設計 MOSS 2007 的頁面 (.aspx) 時,如果要在頁面中加入 C# 程式碼,例如事件:

<%@ Page Language="C#" masterpagefile="~masterurl/default.master" title="未命名 1" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" %>

<script type="text/c#" runat="server">

protected void Button1_Click(object sender, EventArgs e)
{
Button1.Text = DateTime.Now.ToString();
}
</script>

<asp:Content id="Content1" runat="server" contentplaceholderid="PlaceHolderMain">

<asp:Button ID="Button1" runat="server" Height="48px" onclick="Button1_Click"
Text="Button" Width="308px"/>

</asp:Content>

##ReadMore##

在執行時會出現以下錯誤訊息:
image

這是因為在預設的狀況下,MOSS 不允許在頁面中包含 <script> … </script> 的區塊,要解決這個問題,可以修改網站的 web.config 檔,一般是位於 c:\inetpub\wwwroot\wss\VirtualDirectories\80 資料夾下,也就是當初在建立應用程式時所設定的路徑,如下圖最下面的路徑:
image

在 web.config 中找到 <PageParserPaths> 區段,在裡面加入以下設定:

<PageParserPath VirtualPath="/Pages/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />


image

  • VirtualPath="/Pages/*" : 設定 /Pages/ 路徑下的所有 .aspx 頁面都要進行程式碼解析。
  • CompilationMode="Always" : 設定每次都要編譯 .aspx 頁面。
  • AllowServerSideScript="true" : 設定 .aspx 頁面中允許出現 <script> … </script> 的程式碼區塊。
  • IncludeSubFolders="true" : 設定包含 VirtualPath 屬性以下的所有子目錄都有相同的設定。

這樣就可以允許在這個網站下的任何 .aspx 頁面中可以使用 <script> … </script> 的程式碼區塊,就可以撰寫 C# 程式碼了。

2009/07/11 內湖碧山巖-風櫃嘴單車行

今天下午和 watermelon 一起從汐止火車站出發,要騎去內湖碧山巖 –> 風櫃嘴 –> 回汐止,雖然特別選下午 4:00PM 出發,可是太陽還是超級毒的,騎了快九公里才到碧山路,就已經熱到爆:
SANY0001##ReadMore##

開始爬坡前,matermelon 設定一下 GPS 導航,免得迷路了,我則是心中在 OS : "這會不會太陡了啊 ?"
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

果然沒錯,這一路幾乎都是長陡坡,我覺要比之前 2009/05/23 桐花、熊空單車行 的好漢坡要陡多了,而且距離長多了,真是有夠給它硬斗,一路揮汗如雨,中途甚至買了一瓶 600cc 的運動飲料,直接給它乾了,就知道有多缺水了,還好後來山上有雲有樹蔭,要不然應該會直接掛在半路變人乾了。

這次戴了新配的防風眼鏡,由於天色暗了,所以半路把鏡片從黑色墨鏡換成夜間使用黃色鏡片,不過看到照片後才發現一整個怪,還是黑色墨鏡比較順眼。爬到內雙溪森林公園,算是中途高點了,差不多海拔 400 公尺,下次可以帶全家來這邊走走:
SANY0005

接下來就一路下滑,接到往風櫃嘴的路:
SANY0006
SANY0007SANYO DIGITAL CAMERA

沒想到經過之前碧山巖的嚴酷考驗之後,騎風櫃嘴倒變得比較輕鬆了:
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

回到汐止之後,和 watermelon 一起去他介紹的小吃店吃晚餐,第一次吃豬油乾麵,很好吃哩,下次可以再來吃,也第一次吃雞蛋泡泡冰,很特別,有加生雞蛋卻沒有雞蛋味呦,不過倒讓我懷念起台中一中的豐仁冰了,下星期回台中再來去吃吧。

軌跡圖:
軌跡圖

高度表:
高度表

速度表:
速度表

今天的碼錶怪怪的,不知道是那裡秀斗了,常常斷訊,所以也就不準了,所幸還有 GPS 軌䟿記錄,所以就不附上碼錶資訊了。

2009/07/04 金瓜寮單車行

今天本來要去參加 R2066 車聚的,不過早上來不及趕到集合點,所以就全家去金瓜寮騎單車,之前有和弟弟來過 (2009/05/03 金瓜寮自行車道),沒想到雖然是假日,可是金瓜寮單車道卻沒有很多人,而且天氣很好,在金瓜寮車道附近找個地方停車、組裝單車,出發前留影:
SANYO DIGITAL CAMERA##ReadMore##

一開始就是上坡,大家都很努力爬呦:
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

中途休息:
SANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

上次和弟弟來時也有來這邊玩水:
SANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANY0038

到了一個露營區後,大家決定以後要找個時間全家也來露營,不過現在我們要往溪畔自行車道走,沒想到是一連串的爬坡,不行就用牽的吧:
SANY0040SANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

好不容易下坡後找到溪畔自行車道了:
SANYO DIGITAL CAMERA

中午 12 點肚子餓了,先吃點東西補充一下熱量:
SANY0047
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

吃完後繼續騎吧,沒想到後來竟然有一個超級大變態的陡坡:
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

今天大家都很不錯呦,騎了十公里,還爬了山,老婆和小朋友都累壞了,一回家吃完麥當勞,就都上床睡著了。

軌跡圖:
軌跡圖

高度表:
高度表

速度表:
速度表

碼錶資訊:
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA
SANYO DIGITAL CAMERASANYO DIGITAL CAMERA

  • 總時間: 10:10AM ~ 12:20PM
  • 總騎乘時間: 2 小時 10 分
  • 總騎乘距離: 10.5 公里
  • 最高時速: 35.4 公里/小時
  • 平均時速: 9 公里/小時
  •