簡體   English   中英

在web.config中查找會話狀態標簽

[英]finding session state tag in web.config

我需要編寫一個函數,在其中必須在應用程序的web.config中找到會話狀態標記/設置。

我將通過web.config文件作為此函數的參數,函數應檢測到該標記並將其刪除,然后應返回其中沒有會話狀態標記的web.config

我可以使用某些功能或正則表達式來實現此目的嗎?

會話標簽格式:

<sessionState mode="StateServer" stateConnectionString="tcpip=CTSINTCOVOCPRD4:42424" />

要么

<sessionState mode="StateServer" stateConnectionString="tcpip=CTSINTCOVOCPRD4:42424"></sessionState>

這是提取視圖狀態的示例,您可以對其進行修改以拉出會話狀態。

html = Regex.Replace(html, "<div\\s*class=\"aspNetHidden\"[\\s\\S]*?<\\/div\\>", string.Empty, RegexOptions.IgnoreCase);

這是會話狀態的正則表達式:

正則表達式 (在regexhere.net上測試)

<sessionState\s*mode=\"StateServer"\s*stateConnectionString=\"tcpip=([^"]+)"\s*\/>

輸入項

<sessionState mode="StateServer" stateConnectionString="tcpip=CTSINTCOVOCPRD4:42424" />

您可以使函數讀取webconfig,然后使用regex.replace替換狀態字符串[未經個人測試]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM