ASP.NET

出自ProgWiki
於 2022年1月9日 (日) 13:14 由 Player討論 | 貢獻 所做的修訂 →‎字串編碼與解碼
跳至導覽 跳至搜尋

ASP.NET,參照:『維基百科~ASP.NET

技術文件

轉移到Tomcat
天啊!這太神奇了,Tomcat不是JSP在用的Web-Server端嗎?

SDK或RunTime

ASP.NET

  • ASP.NET的版本與Windows版本
ASP.NET版本 相關套件下載 Windows Server 2000 Windows Server 2003 Windows Server 2008 Windows Server 2012
1.0
1.1
  1. .NetFramework 1.1
  2. 語言套件
  3. ServicePack 1
2.0
  1. .NetFramework 2.0
  2. 語言套件
  3. ServicePack 1
2.0+AJAX
  1. 先裝上述2.0的相關套件
  2. ASP.NET 2.0 AJAX Extensions 1.0
3.0
  1. .NetFramework 3.0
3.5
  1. .NetFramework 3.5
  2. 語言套件
  3. ServicePack 1
4.0
  1. .NetFramework 4.0
  2. 語言套件

(SP2)
4.5
  1. .NetFramework 4.5
  2. 語言套件
  • ASP.NET 3.5的擴充套件
  • 官網
  • 套件下載(目前只支援VS2008英文版)
  • 簡介


(例如:「專案追蹤入門套件」、「報表建置入門套件」、「電子商務入門套件」、「入口網站入門套件」。)

ASP.NET AJAX

主條目:ASP.NET AJAX

Gadget


應用

控制項

Other

Framework

WebService

多語系

ASP.NET聊天室

ActiveX控制項

URL

架站套件

檔案

Cache

IP

遠端網站的網頁抓成圖檔

Excel套表用

Regex應用

RSS

Wiki

Log

圖表

其他


其它

FAQ

ASP.NET網站啟用Debug

GridView相關問題

主條目:GridView

先裝.NetFramework再裝IIS,或ASP.NET沒有啟動?

  • 先裝 .NetFramework 再裝 IIS,會導致 ASP.NET 的執行環境無法正常安裝。補救方法如下:
  1. 開始 → 執行→ cmd
  2. cd %windir%\microsoft.net\framework\v2.0.50727
  3. aspnet_regiis -i -enable
  4. 此時便會看到"開始安裝ASP.NET <2.0.50727>"之訊息
  5. 安裝完畢後,再 iisreset

ASP.NET上傳檔案,出現【超出最大的要求長度 】的訊息

  • ASP.NET預設單一檔案上傳上限為 4MB。
  • 在 Web.Config 的<system.web></system.web>之間加上,下列這行。(將上傳的檔案Size放寬到16MB)
<httpRuntime maxRequestLength="16384" /> 


建立 SQL Server 的應用程式服務資料庫

  • 如果有使用到ASP.NET的Login機制與其控制項的話
cd C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
aspnet_regsql.exe

密碼的最小長度應為: 7。必須包含非英數字元: 1。

  • connectionStringName 資料庫連線用字串
  • minRequiredPasswordLength 最小密碼長度
  • minRequiredNonalphanumericCharacters 密碼中, 非英文, 非數字的字元, 最少數量
  • 以下為 web.config 的部分內容
  <membership>
   <providers>
    <remove name="AspNetSqlMembershipProvider" />
    <add connectionStringName="LocalSqlServer" enablePasswordRetrieval="false"
     enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/"
     requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"
     minRequiredPasswordLength="5" minRequiredNonalphanumericCharacters="0"
     passwordAttemptWindow="10" passwordStrengthRegularExpression=""
     name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </providers>
  </membership>
  <roleManager enabled="true">
   <providers>
    <remove name="AspNetSqlRoleProvider" />
    <add connectionStringName="LocalSqlServer" applicationName="/"
     name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
   </providers>
  </roleManager>

Login時,密碼輸入錯誤多次,帳號被鎖住

  • 以下以ASP.NET 2.0的Login控制項預設的SQL資料庫為例。
UPDATE [aspnet_Membership]
	SET [IsLockedOut] = 0
		,[FailedPasswordAttemptCount] = 0
		,[FailedPasswordAnswerAttemptCount] = 0
	FROM [aspnet_Users] AS a, [aspnet_Membership] AS b
	WHERE a.[ApplicationId]=b.[ApplicationId]
		and a.[UserId]=b.[UserId]
		and a.[UserName]='使用者帳號'

如何讓 ASP.NET 使用 Session 資料時不要再自動消失

  • 修改 web.config 檔
<configuration>
  <system.web>
    <sessionState mode="StateServer"
      stateConnectionString="tcpip=localhost:42424"
      cookieless="false"
      timeout="20"/>
  </system.web>
</configuration>
  • 重新啟動服務 aspnet_state
C:\Documents and Settings\Administrator>net start aspnet_state
ASP.NET 狀態服務 服務正在啟動 ..
ASP.NET 狀態服務 服務已經啟動成功。
  • 或是
    1. 「開始」→ 「設定」→「控制台」 → 「系統管理工具」 → 「服務」
    2. 「ASP.NET 狀態服務」 或 「ASP.NET State Service」
    3. 「啟動類型」 改為「自動」後,「套用」再直按「啟動」即可。
以下相關

字串編碼與解碼

編碼種類 編碼 解碼
HTML string strDest = Server.HtmlEncode(strSrc); string strDest = Server.HtmlDecode(strSrc);
URL string strDest = Server.UrlEncode(strSrc); string strDest = Server.UrlDecode(strSrc);

ASP.NET無法連接Oracle資料庫

Q:

System.Data.OracleClient 需有 Oracle 用戶端軟體版本 8.1.7 或以上版本。 
描述: 在執行目前 Web 要求的過程中發生未處理的例外情形。請檢閱堆疊追蹤以取得錯誤的詳細資訊,以及在程式碼中產生的位置。 
例外詳細資訊: System.Exception: System.Data.OracleClient 需有 Oracle 用戶端軟體版本 8.1.7 或以上版本。

A:

  1. 如果ASP.NET要用Oracle,請確認是否給予ASP.NET存取Oracle Client的權限。
  2. 請在檔案總管找到Oracle Client安裝目錄,滑鼠右鍵,內容→安全性,再將ASPNET(WinXP, 若為2003則為Network Service)使用者加入, 並給予權限!

MS-SQL能接受的現在時間格式

  • 用字串包起來
DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss")

跨網站取值

  1. 【來源網站】傳資料給【目的網站】
    Cross-Page Posting in ASP.NET Web Forms | Microsoft Docs
  2. 【目的網站】去抓【來源網站】
    XML Web Services Basics | Microsoft Docs
  3. 其它
    ASP.NET 2.0 的「跨網頁公佈」原理及效能

取得Web.Config設定的變數值

抓appSettings
  • web.config (appSettings 區段通常放在 connectionStrings 區段的上面)
<appSettings> 
	  <add key="WebName" value="This is MyWeb" /> 
</appSettings>
  • 頁面程式(*.aspx.cs)
using System.Web.Configuration; //WebConfigurationManager的命名空間必須
 
//抓 AppSettings 範例
string strWebName = WebConfigurationManager.AppSettings["WebName"];
 
//抓 ConnectionString 範例
string strConnString = WebConfigurationManager.ConnectionStrings["MyDBConnString"].ConnectionString;

避免遊覽器快取網頁

Response.Cache.SetCacheability(HttpCacheability.NoCache);
  • 這樣網頁在輸出時就會加上2個HTTP檔頭
Pragma: No-Cache
Cache-Control: No-Cache

檔案上傳相關

檔案下載相關

修改 web.config 移除 .dll 的檔案下載:
 <system.webServer>
     <staticContent>
         <remove fileExtension=".dll" />
     </staticContent>
 </system.webServer>

文件產生器

ASP.NET網站裡C#與VB.NET併存

IIS出現「HTTP 錯誤 500.19 - Internal Server Error」

動態繫結按鈕事件

ASP.NET資安漏洞

攔截ASP.NET的錯誤訊息

ASP.NET2.0無法正常啟動

  • 無法載入檔案或組件 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 或其相依性的其中之一。 存取被拒。
  • ASP.NET2.0 環境設定問題
  • 或是修改應用程式集區身份視別帳號(在Windows 2003 Server的IIS裡)

更換ASP.NET machineKey

ViewStateException: 無效的 Viewstate

其它