2011年9月28日 星期三

WebSite 與 WebApplication 偵錯時的路徑問題

當使用WebSite專案時,按下偵錯(F5)後,產生的網址會像是這樣
http://localhost:7788/WebSite1/index.aspx

當使用WebApplication專案時,按下偵錯(F5)後,產生的網址會像是這樣
http://localhost:7788/index.aspx


假設在根目錄下有一的名為MyJS.js的javascript文件需要引用
我們在index.aspx裡面下入以下程式碼
<script type="text/javascript" src="/MyJS.js"></script>

當使用WebApplication專案時,一切都沒有問題
若使用WebSite專案時,就會發生錯誤

原因應該很明顯了 ' / ' 代表網站的根目錄
因為WebSite專案自動幫我們加了一個WebSite1的虛擬路徑
而導致錯誤的發生



解決方法:
1. 打開專案的屬性視窗
2. 將'虛擬路徑'屬性 由原先的 ' /WebSite1 '改成' / '
3. 完成

2011年9月22日 星期四

當網站部屬到IIS後 使用jQuery ajax呼叫webService(.asmx)失敗

在本機開發的時候可以正常呼叫,一但部署到IIS上面就發成錯誤
檢查error status為404錯誤

解決方式:
在web.config加入


<configuration>
  <system.web>
    <webServices>
       <protocols>
          <add name="HttpPost" />
       </protocols>
    </webServices>
  </system.web>
</configuration>

2011年9月6日 星期二

呼叫FacebookWebContext.Current 時跳出 !string.IsNullOrEmpty(settings.AppId) 例外

到web.config的<configuration>區段裡面加入以下程式碼:
<configSections>
<section type="Facebook.FacebookConfigurationSection, Facebook" name="facebookSettings"/>
<section name="canvasSettings" type="Facebook.Web.CanvasConfigurationSettings, Facebook.Web" />
</configSections>
<facebookSettings appId="你的appId" appSecret="你的appSecret" />
<canvasSettings
canvasPageUrl="http://apps.facebook.com/smartbuttonthree/"
canvasUrl="https://preview.smartbutton.com/dev/"
authorizeCancelUrl="http://www.facebook.com"/>

注意:<configSections>區段必須放在<configuration>的下面,也就是只能為<configuration>的第一個子區段