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

2025年8月29日 星期五

ASP.NET System.Threading.ThreadAbortException: 執行緒已經中止

 參考引用來源:ASP.NET System.Threading.ThreadAbortException: 執行緒已經中止
---

發生錯誤:執行緒已經中止。     

於 System.Threading.Thread.AbortInternal()

於 System.Threading.Thread.Abort(Object stateInfo)

於 System.Web.HttpResponse.AbortCurrentThread()

於 System.Web.HttpResponse.Redirect(String url, Boolean endResponse, Boolean permanent)

---


解決方案:https://support.microsoft.com/zh-tw/kb/918181

<%@ Page Language="C#" Async="true"%>


當 HttpResponse.Redirect 方法 endResponse 參數不設為 false 時,就會發生這個問題。 根據預設值,endResponse 參數設定為 true。



轉貼連結:http://www.dotblogs.com.tw/boei/archive/2010/07/11/16485.aspx

將網頁轉出成word的時候,最後會來個Response.End()來結束它的輸出,但都會發生<System.Threading.ThreadAbortException> 執行緒已經中止,雖然不會造成系統上的什麼問題。

解決方法:

1.    繼續用Response.End(),外面用try – catch包住,但try – catch會比較消耗資源,所以不考慮。

2.    改用HttpContext.Current.ApplicationInstance.CompleteRequest(),可以跳過Application_EndRequest 事件的執行。

 

如果使用Response.Redirect 或 Server.Transfer 方法也發生一樣狀況的話,就可以使用Response.Redirect(String url, bool endResponse),endResponse就設為False,因為Response.Redirect內部會用到Response.End(),設為False就是要停用Response.End()方法。



2025年8月25日 星期一

ASP.NET C# URL 網址參數解析,取得網址參數

引用來源:ASP.NET C# URL 網址參數解析,取得網址參數 


  1.  底下分別列出解屬性及解析結果
參數結果
Request.ApplicationPath/
Request.Url.Hostmy.url.com
Request.Url.Port8080
Request.Url.Schemehttps
Request.Url.Authoritymy.url.com:8080
Request.Path/Detail/Page/List.aspx/showmore
Request.Url.LocalPath/Detail/Page/List.aspx/showmore
Request.PathInfo/showmore
Request.Url.Query?mid=20
Request.CurrentExecutionFilePath/Detail/Page/List.aspx
Request.FilePath/Detail/Page/List.aspx
Request.RawUrl/Detail/Page/List.aspx/showmore?mid=20
Request.Url.PathAndQuery/Detail/Page/List.aspx/showmore?mid=20
Request.Url.AbsoluteUrihttps://my.url.com:8080/Detail/Page/List.aspx/showmore?mid=20
Request.Url.AbsolutePath/Detail/Page/List.aspx/showmore

  1.  取得系統路徑
參數結果
Request.PhysicalPathC:\wwwroot\Detail\Page\List.aspx
System.IO.Path.GetDirectoryName(Request.PhysicalPath)C:\wwwroot\Detail\Page
Request.PhysicalApplicationPathC:\wwwroot\
System.IO.Path.GetFileName(Request.PhysicalPath)List.aspx

  1.  解析參數
參數結果
Request.Url.Segments/, Detail/, Page/, List.aspx/, showmore


2025年8月23日 星期六

跳轉頁面發生 RegisterForEventValidation 只能在 Render(); 期間呼叫

 跳轉頁面發生:

System.InvalidOperationException: 'RegisterForEventValidation 只能在 Render(); 期間呼叫'

這個問題,可以設定aspx原始檔中<%Page%>的以下兩個設定解決

EnableEventValidation = "false" AutoEventWireup="true"



2025年8月10日 星期日

vs 2022 webform BC30451: Name '' is not declared

 微軟:BC30451: Name '<name>' is not declared

看官網還是看不懂...是什麼問題!

----

參考:錯誤訊息1:BC30451名稱<xxx控制項>未宣告

看了這篇,有些懂了! 是複製造成的!? 

也不全然這樣的問題造成 BC30451

同1支code  ,  A PC Error   但 B PC 卻 OK  

我還在找差異性到底是在哪?

自從開發 webform + web api restful  for framework  就都感覺全不順

單純的 .Net Core 較順...

---------

20250811:

將 B PC OK 的專案(經過更動+儲存)改到 A PC 也OK了...

所以這個 BC30451: Name '<name>' is not declared

應該是無解了...



2024年12月8日 星期日

AutoComplete DropDownList Alternatives In ASP.NET

 請參考來源:AutoComplete DropDownList Alternatives In ASP.NET



asp.net可输入下拉框

 <asp:TextBox ID="TextBox1" runat="server" style="width: 200px; position: absolute"></asp:TextBox>

    <asp:DropDownList ID="DropDownList1" runat="server" onchange="document.getElementById('TextBox1').value=this.options[this.selectedIndex].value" style="width: 217px; clip: rect(auto auto auto 198px); position: absolute">

        <asp:ListItem Value="0"></asp:ListItem>

        <asp:ListItem Value="1">1</asp:ListItem>

        <asp:ListItem Value="2">2</asp:ListItem>

        <asp:ListItem Value="3">3</asp:ListItem>

        <asp:ListItem Value="4">4</asp:ListItem>

    </asp:DropDownList>


DropDownList實現可輸入可選擇

 来源:http://www.cnblogs.com/lengzhan/archive/2016/11/24/6097593.html


1、js版本


<div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); position: absolute">

    <asp:DropDownList ID="ddlModel" runat="server" Style="z-index: -1" Width="105px"

        onchange="getModelTo(this)">

        <asp:ListItem Value="1">SSM-001</asp:ListItem>

        <asp:ListItem Value="2">DDW-523</asp:ListItem>

        <asp:ListItem Value="3">QSD-009</asp:ListItem>

    </asp:DropDownList>

</div>

<asp:TextBox ID="txtModel" runat="server" Style="z-index: 1px; position: absolute"

    Font-Size="9pt" Width="95px" Height="16px" MaxLength="50"></asp:TextBox>

<script type="text/javascript">

    function getModelTo(e) {

        document.getElementById("txtModel").value = e.options[e.selectedIndex].innerText;

        document.getElementById("txtModel").select();

    } 

</script>



2、jquery版本


<div style="z-index: 0; visibility: visible; clip: rect(0px 105px 80px 85px); position: absolute">

    <asp:DropDownList ID="ddlModel" runat="server" Style="z-index: -1" Width="105px"

        onchange="getModelTo(this)">

        <asp:ListItem Value="1">SSM-001</asp:ListItem>

        <asp:ListItem Value="2">DDW-523</asp:ListItem>

        <asp:ListItem Value="3">QSD-009</asp:ListItem>

    </asp:DropDownList>

</div>

<asp:TextBox ID="txtModel" runat="server" Style="z-index: 1px; position: absolute"

    Font-Size="9pt" Width="95px" Height="16px" MaxLength="50"></asp:TextBox>

<script type="text/javascript">

    function getModelTo(e) {

        $("#txtModel").val($("#ddlModel").find("option:selected").text());

        $("#txtModel").select();

    } 

</script>



2024年6月1日 星期六

使用 Knockout.js 建立動態 UI

 使用 Knockout.js 建立動態 UI

---

Introduction to Knockout.js and CRUD Operations in ASP.Net Web Forms Using Knockout.JS

knockout.js-初體驗

Knockstrap


使用 ASP.NET Web API 建置 RESTful API

 使用 ASP.NET Web API 建置 RESTful API

---


理財工程師 Mars 運用工程師能力創造財富自由人生

 理財工程師 Mars 運用工程師能力創造財富自由人生

--

不錯!  

運用工程師能力創造財富自由人生


ASP.Net 的Cookie簡介及用法

 ASP.Net 的Cookie簡介及用法


Cookie(餅乾)是一個在網頁應用程式上拿來儲存瀏覽者資料的做法之一‧ 例如,當一個瀏覽者參觀您的網站時,您就可用Cookie把對方的一些資料儲存起來,並且下一次再使用‧ 另外,如果您有學習過ASP, PHP這類語言的話,相信Cookie對你絕對不陌生‧ 假設您是學習VB, C++的設計師的話,用Cookie就好比是寫資料到使用者的Registry裡一樣‧ 只是用Cookie比較簡單,而且對初學者而言,Cookie也比Registry還容易瞭解!


Cookie事實上是以純文字方式儲存在使用者電腦某資料夾裡面的,以Microsoft Windows NT (2000, XP)的使用者來說,每一個使用者都有一個自己個人的資料夾來放Cookie檔案,而這資料夾通常都會在『C:\Documents and Settings\使用者\Cookies\』這邊‧ 每一個Cookie都儲存著每一個不同網站所存的資料,而每一項所擁有的資料都會不同,這會看網站程式編寫者而定‧ 有時候Cookie會儲存您在某一網站的帳號或密碼、會員身份、登入/登出日期等等‧ 甚至Cookie也可以拿來做是防治瀏覽者重覆投票的防範方法之一!


在使用Cookie上,注意cookie使用也是有一些限制的! 例如一般瀏覽器至少都會支援4096 Bytes的Cookie,允許20個(各網站‧如果您嘗試使用超過更多的Cookie,那麼小心舊的Cookie就會莫名其妙消失!),也許看起來很少,不過基本上卻已經足夠儲存你純文字的資料了! 另外也有一些瀏覽器會有只允許儲存共300 Cookies的限制(所有網站的加起來)‧ 還有,每一個Cookie都會有它的存活時間! 基本上來說,Cookie除了靠網站程式結束外,如果您自己關閉了瀏覽器,那麼Cookie也會自動消失‧ 不過值得慶幸的是您可以自由的設定Cookie的過期時間,這我將會說明!


『筆記:剛才提到了Cookie是儲存在瀏覽者電腦裡面的,所以身為網頁程式編寫者的您,也必須留意到瀏覽者也是會隨意的刪除或想辦法亂修改的! 有時太過相信Cookie的資料內容的話,也可能會導致一些人為問題喔!』



用ASP.Net 寫入一個Cookie資料



假設您是純ASP (Active Server Pages)的學習者,也許在剛開始接觸ASP.Net時可能會有點不習慣! 以Cookie做例子,要閱讀或寫Cookie絕對不是像ASP這樣:


閱讀Cookie資料(ASP):

Dim mycookie : mycookie = Request.Cookies("eat_cookie")


寫入Cookie資料(ASP):

Response.Cookies("eat_cookie") = "C is a cookie!"


在ASP.Net,跟ASP一樣,要寫Cookie都會要使用Response property,要讀用Request‧ 就先講寫入Cookie吧! 如果您想要建立一個Cookie資料,您可以創造單一個Cookie,或在同一時間建多重也是可以(Sub Cookies)‧ 單一的話:

Response.Cookies("mycookie").Value = "C is a cookie!"


要建立一個Sub cookie的話:

Response.Cookies("mycookie")("flavor") = "Coffee"


剛才我有提到Cookie過期的話題,如果要另外加長的話,那麼(假設存活時間設一年):


Response.Cookies("mycookie").Value = "C is a cookie"

Response.Cookies("mycookie").Expires = DateTime.Now().AddDays(365)


註:用Sub cookie也是用類似的方法來設定存活時間


假如我的網站有Sub domain的話,您也可以設定Domain property來分享Cookie:

(例如我的網站叫www.tekcyberspace.com,然後我有一個Sub domain叫forum.tekcyberspace.com)

Response.Cookies("mycookie").Value = "C is a cookie"

Response.Cookies("mycookie").Expires = DateTime.Now().AddDays(365)

Response.Cookies("mycookie").Domain = "forum.tekcyberspace.com"



閱讀Cookie資料



讀Cookie就比較簡單了‧ 我就直接講吧! 假設要讀單一Cookie的話:

Dim get_mycookie As HTTPCookie = Request.Cookies("mycookie")


寫出一個Cookie資料:

Dim get_mycookie As HTTPCookie = Request.Cookies("mycookie")

If Not get_mycookie Is Nothing Then

Response.Write(get_mycookie.Value)

End If

注意如果沒有Cookie在的話,你接受到的會是 Nothing‧


讀取並寫出Sub cookie資料:

Dim get_mycookie As String = Request.Cookies("my_cookie")("flavor")

If not get_mycookie = "" Then

Response.Write(get_mycookie)

End If


Cookie怎麼寫就怎麼讀

  Cookie怎麼寫就怎麼讀


using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;


public partial class B : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            //產生一個Cookie

            HttpCookie cookie = new HttpCookie("test");

            //設定單值

            cookie.Value = Server.UrlEncode("Hello!!世界");

            //設定過期日

            cookie.Expires = DateTime.Now.AddDays(2);

            //寫到用戶端

            Response.Cookies.Add(cookie);


        }

    }



    //讀取cookie(以多值的方式)

    protected void btn_test_Click(object sender, EventArgs e)

    {

        HttpCookie cookie = Request.Cookies["test"];

        foreach (string value in cookie.Values)

        {

            Response.Write("Null?"+(value==null)+"<br/>");/*順便測試看看是否為null還是空字串*/

            Response.Write("空字串?"+(value=="")+"<br/>");

            Response.Write("foreach迴圈中撈出Request.Cookies['test']所有的Value:" + Server.UrlDecode(value)+"<hr/>");

        }


        Response.Write("Null?"+(cookie["test"]==null)+"<br/>");

        Response.Write("空字串?" + (cookie["test"]=="")+"<br/>");

        Response.Write("cookie['test'](HttpCookie物件裡索引名為test的值):"+Server.UrlDecode(cookie["test"])+"<hr/>");

    }

}


2024年4月18日 星期四

Fleck開發的多人網頁版即時聊天室

 Asp.Net Mvc基於Fleck開發的多人網頁版即時聊天室

Fleck 的簡要說明

1、最簡單、最常用的調用方法:(ws://172.10.3.4:8111改成您的伺服器本地IP和埠)


//控制台代碼

var server = new WebSocketServer("ws://172.10.3.4:8111");

server.Start(socket =>

{

  socket.OnOpen = () => Console.WriteLine("產生連接處理");

  socket.OnClose = () => Console.WriteLine("連接斷開處理");

  socket.OnMessage = (message) => {

  //1、此方法用於接收客戶端發送來的消息

  //2、可以做一些自己的操作,例如存入資料庫

  //3、為了響應客戶端,一般會使用下麵的send函數,返迴響應結果。

  socket.Send(message);

  }

});

2、Fleck本身只負責幫你單線聯繫。也就是客戶端A和伺服器建立連接後,會產生一個IWebSocketConnection,也就是上面代碼中socket變數的類型,它包含了接收方法、發送方法,但是都僅限於單一連接內。至於客戶端A想發送消息給客戶端B、C、D亦或者想群發,不好意思Fleck本身不Care。。。當然了那並不是這個功能就不能實現了,只是要開發者自己去把每一個IWebSocketConnection存儲起來,並管理他們的生存周期,通過自己的代碼去實現客戶端A給B發信息或者群發。


3、Fleck不需要額外的容器或進程來運行,它隨著IIS網站運行,也就是在w3wp.exe。至於它是怎麼運行的,目前我還沒有去看源碼,後期有時間再瞧瞧。


 


三、聊天室源碼位置


1、GitHub:https://github.com/DisSunRestart2020/DisSunChat