2008年9月18日 星期四

"build error" allowDefinition='MachineToApplication

http://msdn.microsoft.com/en-us/library/aa479312.aspx

As mentioned before, Visual Studio 2005 normally considers all files in a folder or sub-folder to be part of the Web project. By default, the conversion wizard will create a backup of your Web project in a safe location, but it is possible for the user to overwrite the default. If you put the backup folder in the Web application's folder tree, you will get this somewhat cryptic build error:

Error 1 - It is an error to use a section registered as 
allowDefinition='MachineToApplication' beyond application level

How to fix

Make sure your backup location is not in the Web application's root folder or sub-folder!

2008年9月5日 星期五

WCF 使用ASP.NET 的Session

http://silverlight.net/forums/p/23080/81722.aspx

Hello, session is a server side concept.
Silverlight runs on the client, so it has no
knowledge of the session. But you can pass some
variable from the Silverlight application to the
server via a web service. Then in the web
service, you store it as a session variable.
Later when you call another web service, you can
check the session variable and return it to the
client.

While WCF also has built-in session
support, BasicHttpBinding doesn't support that.
So you need to use ASP.NET session instead. To
enable ASP.NET session on WCF, you need to turn
on ASP.NET Compatibility. Do the following:



  • In web.config, under system.serviceModel
    tag, add this line:


<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>



  • On your service class (not interface), add this attribute:


[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]



  • Now you can use ASP.NET session with the
    following syntax:


HttpContext.Current.Session["YourName"] = something;


object something = HttpContext.Current.Session["YourName"];

2008年7月21日 星期一

WCF HTTPS 出現 404 not found 的問題

最近寫了一個Siverlight 的程式 ,使用 WCF 來連接 IIS Server 上的 Service,但我發現如果是連到 http 的service 則一切正常,但是如果是連到https 就會出現 HTTP 404 Not Found 的錯誤 ,經過不斷的嘗試,終於找到答案了,原來是要在Web.config加上 basicHttpBinding 的定義, 定義如下:


<bindings>

        <basicHttpBinding>

        <!-- Configure basicHttpBinding with Transport security -- >

        <!-- mode and clientCredentialType set to None.-->

           <binding name="Binding1">

               <security mode="Transport">

                   <transport clientCredentialType="None"/>

               </security>

           </binding>

        </basicHttpBinding>

    </bindings>


重點是要將 security mode 設成 Transport,這樣使用HTTPS 來連接這個service 就可以正常了,只是原來出現的 HTTP 404 Not Found 的錯誤,真是讓人怎麼想也想不到是這個問題。

2008年7月8日 星期二

FrontPage 如何 刪去列尾的空白


可以使用 Frontpage 本身的 尋找及取代的功能

1.尋找目標設定為 :b*$

2.勾選 規則運算式(X)

3.按下[全部取代(A)] 就可以了

你也可以將這個查詢規則存檔,下次再load回來,就可以重複用囉

2008年7月3日 星期四

線上轉換 c# 程式碼成HTML Code

http://www.manoli.net/csharpformat/

SilverLight 2.0 如何使用網頁上的 ActiveX control

請參考
http://pietschsoft.com/post/2008/06/Silverlight-and-JavaScript-Interop-Basics.aspx



using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;

namespace DiggSample
{
public partial class Page : UserControl
{
public Page()
{
InitializeComponent();
}

private void Button_Click(object sender, RoutedEventArgs e)
{

}

private void MyButton_Click(object sender, RoutedEventArgs e)
{
MyButton.Content = "按到了!" + DateTime.Now.ToLongTimeString();
//HtmlPage.Window.Alert(HtmlPage.Document.GetElementById("XCsp").version2);
ScriptObject myScriptObject = (ScriptObject) HtmlPage.Window.Eval("XCsp;");
if (myScriptObject != null)
{
HtmlPage.Window.Alert((string)myScriptObject.GetProperty("Version2"));
double bRdrReady = (double)myScriptObject.Invoke("ConnectReader");
if (bRdrReady == 0)
{
myScriptObject.Invoke("ListReaders");
double totalReaders = (double)myScriptObject.GetProperty("inor");
if (totalReaders > 0)
{
for (int i = 0; i < totalReaders; i++)
{
ReaderList.Items.Add(myScriptObject.GetProperty("caReader"+(i+1).ToString()));
}
}
else
{
HtmlPage.Window.Alert("請安裝讀卡機");
}
}
else
{
HtmlPage.Window.Alert("bRdrReader=" + bRdrReady.ToString());
}
}

}
}
}

2008年6月25日 星期三

縮小 UpdatePanel JavaScript size

使用 asp.net 的 UpdatePanel 時, 需要一併引用 ScriptManager 這個Control ,這個Control 有一個 [ScriptMode] 的屬性,如果要讓 AJAX 的 JavaScript size 變小,可以將ScriptMode的值設成Release,這樣可以將MicrosoftAjax.js 的大小從 324KB 戲劇化的變成 88.1KB