finding session state tag in web.config

I need to write a function, where I have to find session state tag/setting in web.config of an application.

I will be passing web.config file as a parameter to this function and function should detect the tag and delete it, then should return web.config without session state tag in it.

Can I have some functionality or regex to achieve this?

Session tag format:

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

or

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

Answers


This is an example for extract viewstate, you can modify this to pull the session state.

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

This is the regex for Session state :

Regex (Tested on regexhere.net)

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

Input

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

You can make a function to read the webconfig and then replace the state string using regex.replace [Not tested personally]


Need Your Help

C# Delegates in Abstract and Subclass

c# delegates abstract-class

I am programming a Programme for Vacations Control for Companies (only to learn, not serious). Now I have a Abstract Class called Employee. and 4 stages of Employees.