2009年7月2日 星期四

執行 ASP.NET 出現 This application is currently offline

執行 ASP.NET 出現下列錯誤訊息
This application is currently offline. To enable the application, remove the app_offline.htm file from the application root directory

說明
Why Take an Application Offline?

There are two main reasons that you would normally want to take your application offline.

To make major changes to the application.(對程式作大幅度的改變)
To gain access to resources that cannot be accessed while in use.(存取相關資源)

讓程式暫時離線的情況有很多種。
例如:程式的架構有很大的改變,無法在不離線的狀態下,完成更新程式的動作。

The app_offline.htm File

在網站的第一層放入app_offline.htm的檔案。這個檔案對ASP.NET 2.0而言,是一個很特別的檔案。當它存在時,ASP.NET 2.0會把它視為程式的根,並關閉其他的程式,以這個程式回應任何使用者傳來的需求。這表示說基本上使用者會被拒絕在應用程式外,此時你可以有時間去對程式作改變。

解決方法
把專案資料夾中 app_offline.htm 檔 刪除即可

參考網頁http://kuanglian2000.wordpress.com/2006/12/22/taking-an-aspnet-20-application-offline%e8%ae%93%e7%b6%b2%e7%ab%99%e7%a8%8b%e5%bc%8f%e7%9f%ad%e6%9a%ab%e9%9b%a2%e7%b7%9a/

2009年6月30日 星期二

JavaScript 的 alert 是亂碼?如何解決 |

通常我們在寫程式時,會希望跳出一些訊息給使用者,但在我的實例中,遇到了跳出的視窗顯示為亂碼!!其代碼如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="950"%>
<%
Dim str
str="登入用戶名不能為空!"
if str<>"" then
response.Write "<script language=JavaScript>alert(""" & str & """);history.go(-1)</script>"
end if
%>

對不起,執行時都會出示亂碼,而不是中文字。(我的網頁採用utf-8編碼,並且在前端加上了Codepage指示詞)
經研究,這是沒有meta設定的關係。即使網頁最前端已有設定%@codepage=65001%,仍然沒用。有時,我的網頁結構特殊,不適合在找地方加上<meta>的設定時(如果可以直接加上meta設定,也可以解決這個問題),可以針對要alert之前,直接塞meta設定在前,這樣,顯示中文就會正常了!!修改如下:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
Dim strMeta
strMeta = "<meta http-equiv=""Content-Type"" content=""text/html; charset=utf-8"" />" '先把meta設定寫在變數strMeta中
str="登入用戶名不能為空!"
if str<>"" then
response.Write strMeta&"<script language=JavaScript>alert(""" & str & """);</script>" '直接加在java script之前,讓中文設定生效
end if
%>

就解決了

2009年6月22日 星期一

Asp.Net C# 加上 JavaScrip 開新視窗,列印

開新視窗,關閉工具列
ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "window.open('ABC.aspx','1234','top=100,left=100,width=720,height=740,toolbar=no');", true);

列印按鈕
ScriptManager.RegisterStartupScript(this, this.GetType(), "print", "javascript: window.print();", true);

彈出式訊息視窗
ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('訊息');", true);

彈出式訊息視窗 + 確認後更換頁面
ScriptManager.RegisterStartupScript(this, this.GetType(), "ALERT", "alert('訊息!');window.location='ABC.aspx?A_Sno=1';", true);

2009年6月17日 星期三

具有潛在危險 Request.Form 的值已從用戶端偵測到

若是出現這樣的錯誤訊息,代表頁面上有文字內容是包含Html這類的語法,通常在使用一些Html的編輯器(留言板、討論區之類常用)做資料送出的動作的時候會發生。

解決辦法如下:

在頁面的Page指示語加入 validateRequest="false"

Ex:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" validateRequest="false" %>

2009年6月16日 星期二

C# (ascx) usercontrol互相傳值

話說兩個不相信任的政黨..要互相移交政權..要好好的傳地下去..是有點給它難..
話說兩個不相關的usercontrol要互相丟值接值..感覺起來也是不怎麼好用..

google一下..可以發現有人提供一些方法..像interface這樣很正統的解決方法..不過.. 真的有點給它努力認真研究.. 才可以給它懂(我就是這樣懂的....) 如果看不懂或是想偷懶..那有啥方法呢?..有低..session..application都可以解決..

textbox.ascx..這一個usercontrol放一個textbox和一個button
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="textbox.ascx.cs" Inherits="usercontrol_textbox" %>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />

textbox.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
HttpContext.Current.Items["textbox"] = TextBox1.Text;
}

label.ascx..這一個usercontrol放一個label
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="label.ascx.cs" Inherits="usercontrol_label" %>
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

label.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{

}
void Page_PreRender(object sender, EventArgs e)
{
Label1.Text = (string)HttpContext.Current.Items["textbox"];
}

CurrentItems.aspx..這裡把兩個usercontrol放進來..

<form id="form1" runat="server">
<div>
<uc1:textbox ID="textbox1" runat="server" />
<br />
<uc2:label ID="label1" runat="server" />
</div>
</form>

執行就可以抓到值啦
這裡就是用HttpContext.Current.Items["abc"]這東西..

參考:
http://msdn2.microsoft.com/zh-tw/library/system.web.httpcontext.items.aspx

(asp net)(c#) 讀取文字檔

asp net
一行一行的取讀取文字檔內的資料,並將所取的值回傳
Private Function GetTextString() As String
Dim value As String = ""
'Dim a As String = ""
Dim MySF As IO.StreamReader = New IO.StreamReader("c:1.txt", System.Text.Encoding.Default)
'value = MySF.ReadToEnd()
'讀取全部會包含換行符號
Do While Not MySF.EndOfStream
'讀取單行
value = MySF.ReadLine
Loop
Return value
End Function

c#
一行一行的取讀取文字檔內的資料
StreamReader stmRdr = new StreamReader("TextFile1.txt");

string line = stmRdr.ReadLine();
while(line != null) {
Console.WriteLine(line);
line = stmRdr.ReadLine();
}

2009年6月15日 星期一

好用的 MS SQL 2005 欄位字串加密應用 ( MD5 與 SHA1 )

MS SQL 2005 字串加密函式 -- HashBytes

HashBytes提供的加密法有幾種 (MD2、MD4、MD5、SHA、SHA1 ),但最常使用的還是 MD5 與 SHA1。而整個使用過程的感覺來說,基本上還算簡單~只是有一些"眉角"要注意。首先先測試 HashBytes 運作是否合乎需求:

select hashbytes('MD5','12345') as MD5,hashbytes('SHA1','12345') as SHA1

2009年6月13日 星期六

FLASH與ASP間的資料傳遞

要用FLASH和ASP作互動(client端&server端之連結)
讓使用者輸入ID,將ID傳到ASP,再從ASP把值傳回來。
(軟體分別使用Flash MX2004 和 Visual Web Developer 2008 Express版)

想法:
用FLASH第一個影格裡製作一個文字輸入欄(id_txt)和按鈕(ok_btn),輸入文字按下按鈕後,即可將所輸入的文字傳到ASP的Label。
ASP再將值傳回FLASH的第二個影格的動態文字框(receive_mc)。
-----------------第一個影格時間軸程式碼--------------------
stop();
var username = new LoadVars();
id_txt.onData = function(){
}
ok_btn.onRelease = function() {
loadVariables(Default.aspx, post);
_root.gotoAndPlay(2);
}
--------------------------------------------------------------------------

-----------第二個影格的動態文字框接收傳回值-----------

onClipEvent(load)
{
CurrentRecord = 0;
loadVariables ("Default.aspx", get);
}
onClipEvent(data)
{
strusername=username;
strPosition = "Record " add String(CurrentRecord+1) add " of " add String(TotalRecords);
}
--------------------------------------------------------------------------

--------------------------ASP的Label內容--------------------------
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim id_txt As String = ""
id_txt = Request("id_txt")
Response.Write(id_txt)
End Sub

End Class
--------------------------------------------------------------------------

改用下面的方法
var result_lv:LoadVars = new LoadVars();//先宣告一個容器用來接收資料
result_lv.onLoad = function(success:Boolean) {
if (success) {//如果載入成功
result_ta.text = result_lv.welcomeMessage;//result_lv是容器、welcomeMessage是傳回的變數 (請依實際情況做修改)
} else {//如果載入失敗
result_ta.text = "連線失敗";
}
};
var send_lv:LoadVars = new LoadVars();//宣告一個容器存放要傳出的資料
send_lv.name = name_ti.text;//send_lv是容器、name是要傳出的變數名稱 (請依實際情況做修改)

下面這一行你可以寫在按鈕的 onRelease 裡

send_lv.sendAndLoad("filename.asp",result_lv,"POST");

ASP的部份
你要接收 POST 進來的 name 變數,然後做你想做的處理
要傳資料給FLASH
就把資料輸出到頁面上、FLASH就會接收到

輸出的格式如下
變數名稱=值
如果有多個變數就用 & 分隔
變數名稱1=值&變數名稱2=值&變數名稱3=值

不要輸出不必要的東西在畫面上

Q:要怎麼把值丟進去?
A:上面的程式碼就可以將資料丟給ASP。

Q:他要怎麼接收flash丟出來的值?
看你貼的程式碼、我以為你會寫ASP
ASP不是我的專長、但我搜尋的結果應該是下面這句

Request.Form("變數")

如果FLASH傳出來的變數叫做 name
那ASP就用Request.Form("name")取得傳入的資料