I Have a HtmlHelper code like below
sskIconsHtml +=
"<a href=\"#\" class=\"ssk ssk-twitter social-icon si-borderless si-text-color si-twitter\" title=\"Twitter\"";
sskIconsHtml += (socialSharing != null && !string.IsNullOrEmpty(socialSharing.TwitterShortenedUrl))
? " data-url=\"" + socialSharing.TwitterShortenedUrl + "\""
: string.Empty;
sskIconsHtml += " data-text=''";
sskIconsHtml += (socialSharing != null && !string.IsNullOrEmpty(socialSharing.TwitterText))
? " data-title=\"" + socialSharing.TwitterText + "\""
: string.Empty;
sskIconsHtml +=
" ><i class=\"icon-twitter\"></i><i class=\"icon-twitter\"></i></a>";
If you see the data-text I am passing a value of empty string But where it rendered in the browser it is rendering like below see the data-text property.
<i class="icon-twitter"></i><i class="icon-twitter"></i>
Related
We used to write code in .Net Framework for DataTable filtering on server side.
This was the old code where HttpContext.Request was working fine. Now in .Net 6 how we can establish the same search and get HttpContext as well in any controller or model class from jquery.
This function is static and I am stuck in HttpContext.Request line where this is throwing exception "Httpcontext does not exist" even if we use IHttpContextAccessor here. How can we access that variable as that is defined in Program.cs.
public static DataTable FilterTable(DataTable dt, ref int Fcount, JQPM p)
{
p.sColumnslist = p.sColumns.Split(',');
string Fstring = ""; Int32 intVal = 0;
if (!string.IsNullOrEmpty(p.sSearch))
{
string[] Arr = p.sSearch.Trim().Split(' ');
for (int i = 0; i < Arr.Length; i++)
{
if (Arr[i] != "")
{
Fstring = "0=1 ";
for (int j = 0; j < p.sColumnslist.Length; j++)
{
if (Convert.ToBoolean(System.Web.HttpContext.Request["bSearchable_" + j]))
{
if (dt.Columns[p.sColumnslist[j]].DataType.Name == "String")
{
Fstring += " or " + p.sColumnslist[j] + " LIKE '%" + Arr[i] + "%'";
}
else if (dt.Columns[p.sColumnslist[j]].DataType.Name == "DateTime")
{
Fstring += " or " + p.sColumnslist[j] + "Format LIKE '%" + Arr[i] + "%'";
}
else
{
if (Int32.TryParse(Arr[i], out intVal))
{
Fstring += " or " + p.sColumnslist[j] + " = " + intVal;
}
}
}
}
//Fstring += " PartyName LIKE '%" + Arr[i] + "%'";
//if (Int32.TryParse(Arr[i], out intVal))
//{
// Fstring += " or SaleVoucherNo = " + intVal;
//}
//Fstring += " or SaleDateFormat LIKE '%" + Arr[i] + "%'";
//dt = GetDatatable(dt, Fstring, ref Fcount, p); Fstring = "";
dt = SearchDatatable(dt, Fstring, ref Fcount, p); Fstring = "";
}
}
}
//else
//{
//dt = GetDatatable(dt, Fstring, ref Fcount, p);
dt = GetDatatable(dt, ref Fcount, p);
//}
return dt;
}
System.Web.HttpContext has changed to Microsoft.AspNetCore.Http.HttpContext; you will need to pass the instance of this from where HttpContext is available into this function.
public static DataTable FilterTable(DataTable dt, ref int Fcount, JQPM p)
becomes
public static DataTable FilterTable(Microsoft.AspNetCore.Http.HttpContext httpContext, DataTable dt, ref int Fcount, JQPM p)
If you are retrieving "bSearchable_" + j from the QueryString and it will only contain that key once you can then use
httpContext.Request.Query["bSearchable_" + j].ToString();
where httpContext is the instance you pass in.
See:
https://learn.microsoft.com/en-us/aspnet/core/migration/http-modules?view=aspnetcore-6.0#migrating-to-the-new-httpcontext
https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-context?view=aspnetcore-6.0
I am making a companion app for a Monopoly-esque game I'm designing. My goal is to have all the properties have a MovieClip that displays who owns it and how much it has been upgraded. There are literally hundreds of properties, and each one bogs down my run time by about a second (I set up a 1-sec timer to see how long it takes to run).
I have a MovieClip that will "spawn in" each property as I need. The idea being, I have a button that tells this MC to go to frame 10, and frame 10 will have code that adds the child for Property 10, and then that child contains all the necessary code. This child spawning MC looks like this:
import flash.events.MouseEvent;
import flash.events.Event;
stop();
// I used a "fakeChild" as a placeholder to get something spawned in so that there is something to be removed
var fake_Child: fakeChild = new fakeChild();
var property_Pale15: propertyPale15 = new propertyPale15();
var property_Red15: propertyRed15 = new propertyRed15();
removeChildAt(1);
addChildAt(fake_Child, 1);
And every subsequent frame for a given property looks like this (the property in this case is "Pale 15")
removeChildAt(1);
addChildAt(property_Pale15, 1);
property_Pale15.newData();
property_Pale15.propertyOwner();
I currently only have two test properties, and each one bogs down my timer by about a second, which is very bad. The properties themselves have an immense amount of code, which looks like this:
import flash.events.MouseEvent;
import flash.ui.Mouse;
import flash.events.Event;
stop();
var myPropertyData:SharedObject = SharedObject.getLocal("myLocalData");
var propertyName: String = ("Pale 15");
propertyDisplay.text = propertyName;
var propertyValue: int;
var propertyRent: int;
var activePlayer: int;
var currentRank: int;
loadData();
btnProperty.addEventListener(MouseEvent.CLICK, activateProperty);
function activateProperty(e:MouseEvent):void{
propertyValue = MovieClip(root).valuePale15;
if(MovieClip(root).buyupgradeAction == true && loanedProperty.visible == false){
buyupgradeProperty();
}else if(MovieClip(root).paycostAction == true && bridgeProperty.visible == false && loanedProperty.visible == false){
paycostProperty();
}
}
function buyupgradeProperty(e:MouseEvent = null){
// Active Player (if Owner) Upgrades Property
if(activePlayer == 1 && MovieClip(root).activePlayer == 1 && currentRank < 10){
MovieClip(root).myLocalData.data.moneyDisplay1 -= propertyValue * 0.8;
currentRank += 1;
currentRankDisplay.text = currentRank;
propertyRent = propertyValue * currentRank * currentRank * 0.1;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay1 + " upgraded " + propertyName + " to Rank " + currentRank + " for $" + propertyValue * 0.8 + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(activePlayer == 2 && MovieClip(root).activePlayer == 2 && currentRank < 10){
MovieClip(root).myLocalData.data.moneyDisplay2 -= propertyValue * 0.8;
currentRank += 1;
currentRankDisplay.text = currentRank;
propertyRent = propertyValue * currentRank * currentRank * 0.1;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay2 + " upgraded " + propertyName + " to Rank " + currentRank + " for $" + propertyValue * 0.8 + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(activePlayer == 3 && MovieClip(root).activePlayer == 3 && currentRank < 10){
MovieClip(root).myLocalData.data.moneyDisplay3 -= propertyValue * 0.8;
currentRank += 1;
currentRankDisplay.text = currentRank;
propertyRent = propertyValue * currentRank * currentRank * 0.1;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay3 + " upgraded " + propertyName + " to Rank " + currentRank + " for $" + propertyValue * 0.8 + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(activePlayer == 4 && MovieClip(root).activePlayer == 4 && currentRank < 10){
MovieClip(root).myLocalData.data.moneyDisplay4 -= propertyValue * 0.8;
currentRank += 1;
currentRankDisplay.text = currentRank;
propertyRent = propertyValue * currentRank * currentRank * 0.1;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay4 + " upgraded " + propertyName + " to Rank " + currentRank + " for $" + propertyValue * 0.8 + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}
// Active Player buys Property
if(MovieClip(root).activePlayer == 1 && currentFrame == 1){
MovieClip(root).myLocalData.data.moneyDisplay1 -= propertyValue;
MovieClip(root).myLocalData.data.propertyDisplay1 += 1;
gotoAndStop(2);
MovieClip(root).stageProperties.propertyColor.color = (0xFF0000);
colorChange();
propertyRent = 0;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay1 + " purchased " + propertyName + " for $" + propertyValue + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 2 && currentFrame == 1){
MovieClip(root).myLocalData.data.moneyDisplay2 -= propertyValue;
MovieClip(root).myLocalData.data.propertyDisplay2 += 1;
gotoAndStop(3);
MovieClip(root).stageProperties.propertyColor.color = (0x0000FF);
colorChange();
propertyRent = 0;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay2 + " purchased " + propertyName + " for $" + propertyValue + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 3 && currentFrame == 1){
MovieClip(root).myLocalData.data.moneyDisplay3 -= propertyValue;
MovieClip(root).myLocalData.data.propertyDisplay3 += 1;
gotoAndStop(4);
MovieClip(root).stageProperties.propertyColor.color = (0x00FF00);
colorChange();
propertyRent = 0;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay3 + " purchased " + propertyName + " for $" + propertyValue + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 4 && currentFrame == 1){
MovieClip(root).myLocalData.data.moneyDisplay4 -= propertyValue;
MovieClip(root).myLocalData.data.propertyDisplay4 += 1;
gotoAndStop(5);
MovieClip(root).stageProperties.propertyColor.color = (0xFFFF00);
colorChange();
propertyRent = 0;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay4 + " purchased " + propertyName + " for $" + propertyValue + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}
saveData();
}
function paycostProperty(e:MouseEvent = null){
if(MovieClip(root).activePlayer == 1 && activePlayer == 2){
MovieClip(root).myLocalData.data.moneyDisplay1 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay2 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay1 + " paid " + MovieClip(root).myLocalData.data.nameDisplay2 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 1 && activePlayer == 3){
MovieClip(root).myLocalData.data.moneyDisplay1 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay3 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay1 + " paid " + MovieClip(root).myLocalData.data.nameDisplay3 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 1 && activePlayer == 4){
MovieClip(root).myLocalData.data.moneyDisplay1 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay4 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay1 + " paid " + MovieClip(root).myLocalData.data.nameDisplay4 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 2 && activePlayer == 1){
MovieClip(root).myLocalData.data.moneyDisplay2 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay1 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay2 + " paid " + MovieClip(root).myLocalData.data.nameDisplay1 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 2 && activePlayer == 3){
MovieClip(root).myLocalData.data.moneyDisplay2 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay3 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay2 + " paid " + MovieClip(root).myLocalData.data.nameDisplay3 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 2 && activePlayer == 4){
MovieClip(root).myLocalData.data.moneyDisplay2 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay4 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay2 + " paid " + MovieClip(root).myLocalData.data.nameDisplay4 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 3 && activePlayer == 1){
MovieClip(root).myLocalData.data.moneyDisplay3 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay1 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay3 + " paid " + MovieClip(root).myLocalData.data.nameDisplay1 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 3 && activePlayer == 2){
MovieClip(root).myLocalData.data.moneyDisplay3 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay2 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay3 + " paid " + MovieClip(root).myLocalData.data.nameDisplay2 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 3 && activePlayer == 4){
MovieClip(root).myLocalData.data.moneyDisplay3 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay4 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay3 + " paid " + MovieClip(root).myLocalData.data.nameDisplay4 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 4 && activePlayer == 1){
MovieClip(root).myLocalData.data.moneyDisplay4 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay1 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay4 + " paid " + MovieClip(root).myLocalData.data.nameDisplay1 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 4 && activePlayer == 2){
MovieClip(root).myLocalData.data.moneyDisplay4 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay2 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay4 + " paid " + MovieClip(root).myLocalData.data.nameDisplay2 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}else if(MovieClip(root).activePlayer == 4 && activePlayer == 3){
MovieClip(root).myLocalData.data.moneyDisplay4 -= propertyRent;
MovieClip(root).myLocalData.data.moneyDisplay3 += propertyRent;
MovieClip(root).transactionLog = (MovieClip(root).myLocalData.data.nameDisplay4 + " paid " + MovieClip(root).myLocalData.data.nameDisplay3 + " $" + propertyRent + " for landing on " + propertyName + " (" + MovieClip(root).Time_txt.text + ")")
MovieClip(root).updateLogs();
}
saveData();
}
function saveData(e:MouseEvent = null){
myPropertyData.data.Pale15Rent = propertyRent;
myPropertyData.data.Pale15Rank = currentRank;
myPropertyData.data.Pale15Frame = currentFrame;
myPropertyData.data.Pale15Loan = loanedProperty.visible;
myPropertyData.data.Pale15Bridge = bridgeProperty.visible;
myPropertyData.flush();
}
function loadData(e:Event = null){
propertyRent = myPropertyData.data.Pale15Rent;
currentRank = myPropertyData.data.Pale15Rank;
gotoAndStop(myPropertyData.data.Pale15Frame);
loanedProperty.visible = myPropertyData.data.Pale15Loan;
bridgeProperty.visible = myPropertyData.data.Pale15Bridge;
}
function newData(e:Event = null){
if(MovieClip(root).gameSave == 1){
myPropertyData.data.Pale15Rent = 0;
myPropertyData.data.Pale15Rank = 0;
myPropertyData.data.Pale15Frame = 1;
myPropertyData.data.Pale15Loan = false;
myPropertyData.data.Pale15Bridge = false;
loadData();
}
}
function propertyOwner(e:Event = null){
if(activePlayer == 1){
MovieClip(root).stageProperties.propertyColor.color = (0xFF0000);
colorChange();
}else if(activePlayer == 2){
MovieClip(root).stageProperties.propertyColor.color = (0x0000FF);
colorChange();
}else if(activePlayer == 3){
MovieClip(root).stageProperties.propertyColor.color = (0x00FF00);
colorChange();
}else if(activePlayer == 4){
MovieClip(root).stageProperties.propertyColor.color = (0xFFFF00);
colorChange();
}
}
function colorChange (e:MouseEvent = null){
MovieClip(root).stageProperties.Pale15.transform.colorTransform = MovieClip(root).stageProperties.propertyColor;
}
I tried to keep the code as general as possible so I could copy and paste for the other properties. Currently, this property is able to be purchased, upgraded, and dish out rent to the proper players based on what buttons are active, as well as tell a "Property Display" to change colors on the board based on who owns what.
Note: I have used AS3 for a very long time, but have no formal training, it is all self taught. I have tried many many times to understand how "parent/child/private class/etc" work, and I cannot grasp it. I wonder if there is a better way to do what I'm trying to do.
Ok, let me write some scripts in order to explain what OOP-thinking is about. Also, I strongly advise you to read and understand the idea of MVC pattern because scripts below represent [M] and [C], while [V] is not really important and adding it later on is not too difficult too as long as you have the architecture of your application straight.
First, let's define the gameboard cell, a place the players can pass by or visit.
package
{
// A data [M]odel class.
public class Place
{
// What do we call this place.
public var title:String = "";
// A guest list.
public var visitors:Array = new Array;
// The Person class will be defined later.
public function visit(who:Person):void
{
// Add the guest to the list of visitors.
visitors.push(who);
}
public function leave(who:Person):void
{
// Remove the visitor and remove its location record.
var anIndex:int = visitors.indexOf(who);
visitors.splice(anIndex, 1);
}
}
}
Person class so it would be able to visit and leave places.
package
{
// A data [M]odel class.
public class Person
{
// Personal name.
public var title:String = "";
// A place of residence.
public var stayingAt:Place;
}
}
To glue them together we need some controller that allows to move people from place to place. The idea is to NEVER address the [M] objects Person and Place directly, so the [C] script below ensures that a Person is always leaving and visiting properly, doesn't sit over 10 Places, etc.
package
{
// A [C]ontroller class.
public class City
{
// City name.
public var title:String = "";
public function move(who:Person, where:Place):void
{
// Remove the guest from where it is currently staying.
if (who.stayingAt)
{
who.stayingAt.leave(who);
who.stayingAt = null;
}
where.visit(who);
who.stayingAt = where;
}
}
}
Now, in terms of Monopoly, what a Building is? It is a kind of Place, but with more complicated behavior. Then a Player is a Person who has money, can own buildings ant take turns to do things.
package
{
// A data [M]odel class.
public class Player extends Person
{
public var money:int;
public var color:uint;
public var turnsToAct:int;
// A list of owned buildings.
public var owns:Array = new Array;
// Charges money from the Player
// then returns how much was actually charged.
public function charge(value:int):int
{
var acharge:int = 0;
if (value <= 0)
{
// You cannot charge non-positive sums.
}
else if (money - value < 0)
{
// Bankruptcy handling block.
acharge = Math.max(0, money);
turnsToAct = 1000000;
money -= value;
}
else
{
acharge = value;
money -= value;
}
return acharge;
}
}
}
So, a Building be like...
package
{
// A data [M]odel class.
public class Building extends Place
{
public var owner:Player;
public var color:uint;
public var cost:int;
public var rent:int;
public function purchase(who:Player):void
{
who.charge(cost);
owner = who;
color = owner.color;
}
// Building can take rent from a visiting Player.
// So, the "visit" method needs some additional behavior.
override public function visit(who:Person):void
{
// Invoke previously defined visit logic.
super.visit(who);
// If the Building is not owned, there's no rent.
// There's also no rent, if the owner visits.
if (!owner || who == owner) return;
// Person class does not have "charge" method. Read up "typecasting".
// The following one line is actually that HORRIBLE block
// of code named "paycostProperty" in your question.
owner.money += (who as Player).charge(rent);
// Seriously.
}
}
}
So, there are some things left to do (I am getting lazy and not going to program here the whole Monopoly thing):
Devise City.init() method so that it creates an ordered list of Players, an ordered list of Places and Buildings and moves all the Players to the first cell.
Compose the logic to control turns and the flow of the Player taking its turn: cast a die, move, make decisions, complete its turn.
Design the [V] components to display Players' stats, Places and Buildings with all their possible states, the City to visualise the overall state of things.
I would like to select all nodes, that have text in them.
In this example the outer shouldBeIgnored tag, should not be selected:
<shouldBeIgnored>
<span>
the outer Span should be selected
</span>
</shouldBeIgnored>
Some other posts suggest something like this: //*/text().
However, this doesn't work in firefox.
This is a small UnitTest to reproduce the problem:
public class XpathTest {
final WebDriver webDriver = new FirefoxDriver();
#Test
public void shouldNotSelectIgnoredTag() {
this.webDriver.get("http://www.s2server.de/stackoverflow/11773593.html");
System.out.println(this.webDriver.getPageSource());
final List<WebElement> elements = this.webDriver.findElements(By.xpath("//*/text()"));
for (final WebElement webElement : elements) {
assertEquals("span", webElement.getTagName());
}
}
#After
public void tearDown() {
this.webDriver.quit();
}
}
If you want to select all nodes that contain text then you can use
//*[text()]
Above xpath will look for any element which contains text. Notice the text() function which is used to determine if current node has text or not.
In your case it will select <span> tag as it contains text.
You can call a javascript function, which shall return you text nodes:
function GetTextNodes(){
var lastNodes = new Array();
$("*").each(function(){
if($(this).children().length == 0)
lastNodes.push($(this));
});
return lastNodes;
}
Selenium WebDriver code:
IJavaScriptExecutor jscript = driver as IJavaScriptExecutor;
List<IWebElement> listTextNodes = jscript.ExecuteScript("return GetTextNodes();");
FYI: Something like might work for you.
I see no reason why this wouldn't work
(by java)
text = driver.findElement(By.xpath("//span")).getText()
If in the odd case that doesnt work:
text = driver.findElement(By.xpath("//span")).getAttribute("innerHTML")
Finally i found out that there is no way to do it with xpath (because XPaths text() selects also the innerText of a node). As workaround i have to inject Java Script that returns all elements, selected by an XPath, that has some text.
Like this:
public class XpathTest
{
//#formatter:off
final static String JS_SCRIPT_GET_TEXT = "function trim(str) { " +
" return str.replace(/^\s+|\s+$/g,''); " +
"} " +
" " +
"function extractText(element) { " +
" var text = ''; " +
" for ( var i = 0; i < element.childNodes.length; i++) { " +
" if (element.childNodes[i].nodeType === Node.TEXT_NODE) { " +
" nodeText = trim(element.childNodes[i].textContent); " +
" " +
" if (nodeText) { " +
" text += element.childNodes[i].textContent + ' '; " +
" } " +
" } " +
" } " +
" " +
" return trim(text); " +
"} " +
" " +
"function selectElementsHavingTextByXPath(expression) { " +
" " +
" result = document.evaluate(\".\" + expression, document.body, null, " +
" XPathResult.ANY_TYPE, null); " +
" " +
" var nodesWithText = new Array(); " +
" " +
" var node = result.iterateNext(); " +
" while (node) { " +
" if (extractText(node)) { " +
" nodesWithText.push(node) " +
" } " +
" " +
" node = result.iterateNext(); " +
" } " +
" " +
" return nodesWithText; " +
"} " +
"return selectElementsHavingTextByXPath(arguments[0]);";
//#formatter:on
final WebDriver webDriver = new FirefoxDriver();
#Test
public void shouldNotSelectIgnoredTag()
{
this.webDriver.get("http://www.s2server.de/stackoverflow/11773593.html");
final List<WebElement> elements = (List<WebElement>) ((JavascriptExecutor) this.webDriver).executeScript(JS_SCRIPT_GET_TEXT, "//*");
assertFalse(elements.isEmpty());
for (final WebElement webElement : elements)
{
assertEquals("span", webElement.getTagName());
}
}
#After
public void tearDown()
{
this.webDriver.quit();
}
}
I modified the UnitTest that the example testable.
One problem with locating text nodes is that even empty strings are considered as valid text nodes (e.g
<tag1><tag2/></tag1>
has no text nodes but
<tag1> <tag2/> </tag1>
has 2 text nodes, one with 2 spaces and another with 4 spaces )
If you want only the text nodes that have non-empty text, here is one way to do it:
//text()[string-length(normalize-space(.))>0]
or to get their parent elements
//*[text()[string-length(normalize-space(.))>0]]
I have java script which create select box depend of ajax result.
For example, if result = 2x combo, i create 2x select box via javascript.
if (this.Type == "combo") {
var result = "<label>" + this.Name + "</label><select onChange='ProChange(this)' name='" + this.ID + "'>";
result += "<option value='0'>Please select</option>";
for (var i = 0; i < this.Values.length; i++) {
var resultId = this.Values[i].ID;
var resultName = this.Values[i].Name;
result += "<option value= " + resultId + ">" + resultName + "</option>";
}
result += "<option value='-1'>Other</option>";
result += "<input type='text' name='"+this.ID+"other' style='display:none;' id='"+this.ID+"' />";
result += "</select>";
So my main question is, can i apply telerik style on dynamic created select box?
You can use the Telerik RadFormDecorator
<telerik:RadFormDecorator ID="rfd_combo" runat="server" DecoratedControls="Select" />
and after creating your controls by javascript:
$find("<%= rfd_combo.ClientID %>").decorate();
More details: http://www.telerik.com/support/kb/aspnet-ajax/formdecorator/decorate-dynamically-added-controls-by-using-radformdecorator.aspx
I have been successful in posting to CA SiteMinder from the client, however, when I attempt to do a server side post I get no response from the server, but I do get a Status 200 (OK). I should be getting SMSESSION back in the response, or response headers. I get nothing back from the post. So, my code is as follows (I posted my entire code behind file, just review the server side post method):
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Services;
using System.Text;
using System.Net;
using System.IO;
using System.Collections;
namespace SiteMinder_SiteMinder_Side
{
public partial class login : System.Web.UI.Page
{
com.ezmultifactor.demoappliance.Service1 service = new com.ezmultifactor.demoappliance.Service1();
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Cookies["reauthen"] == null)
{
Response.Redirect(ConfigurationManager.AppSettings["secureauthUri"] + "?returnSession="+Server.UrlEncode(Request.QueryString["target"].Replace("-SM-","").Replace("$SM$","")));
}
else
{
LoadSession();
if (ConfigurationManager.AppSettings["ClientOrServerPost"] == "client")
{
ClientPost();
}
if (ConfigurationManager.AppSettings["ClientOrServerPost"] == "server")
{
ServerPost();
}
}
}
protected string createPramString()
{
String Params = String.Empty;
Params+=(String)Session["userName"]+"="+ Server.UrlEncode((String)Session["userNameValue"]);
Params+="&"+(String)Session["password"]+"="+ Server.UrlEncode((String)Session["passwordValue"]);
if ((String)Session["name1"] != "e" && (String)Session["value1"] != "e")
{
Params += "&" + (String)Session["name1"] + "=" + Server.UrlEncode((String)Session["value1"]);
}
if ((String)Session["name2"] != "e" && (String)Session["value2"] != "e")
{
Params += "&" + (String)Session["name2"] + "=" + Server.UrlEncode((String)Session["value2"]);
}
if ((String)Session["name3"] != "e" && (String)Session["value3"] != "e")
{
Params += "&" + (String)Session["name3"] + "=" + Server.UrlEncode((String)Session["value3"]);
}
if ((String)Session["name4"] != "e" && (String)Session["value4"] != "e")
{
Params += "&" + (String)Session["name4"] + "=" + Server.UrlEncode((String)Session["value4"]);
}
if ((String)Session["name5"] != "e" && (String)Session["value5"] != "e")
{
Params += "&" + (String)Session["name5"] + "=" + Server.UrlEncode((String)Session["value5"]);
}
if ((String)Session["name6"] != "e" && (String)Session["value6"] != "e")
{
Params += "&" + (String)Session["name6"] + "=" + Server.UrlEncode((String)Session["value6"]);
}
if ((String)Session["name7"] != "e" && (String)Session["value7"] != "e")
{
Params += "&" + (String)Session["name7"] + "=" + Server.UrlEncode((String)Session["value7"]);
}
if ((String)Session["name8"] != "e" && (String)Session["value8"] != "e")
{
Params += "&" + (String)Session["name8"] + "=" + Server.UrlEncode((String)Session["value8"]);
}
if ((String)Session["name9"] != "e" && (String)Session["value9"] != "e")
{
Params += "&" + (String)Session["name9"] + "=" + Server.UrlEncode((String)Session["value9"]);
}
if ((String)Session["name10"] != "e" && (String)Session["value10"] != "e")
{
Params += "&" + (String)Session["name10"] + "=" + Server.UrlEncode((String)Session["value10"]);
}
if ((String)Session["name11"] != "e" && (String)Session["value11"] != "e")
{
Params += "&" + (String)Session["name11"] + "=" + Server.UrlEncode((String)Session["value11"]);
}
if ((String)Session["name12"] != "e" && (String)Session["value12"] != "e")
{
Params += "&" + (String)Session["name12"] + "=" + Server.UrlEncode((String)Session["value12"]);
}
if ((String)Session["name13"] != "e" && (String)Session["value13"] != "e")
{
Params += "&" + (String)Session["name13"] + "=" + Server.UrlEncode((String)Session["value13"]);
}
return Params;
}
protected void ServerPost()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create((String)Session["PostURL"]);
request.Method = "POST";
string postData = createPramString();
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
//request.PreAuthenticate = true;
//request.Credentials = CredentialCache.DefaultCredentials;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Response.Write(((HttpWebResponse)response).GetResponseHeader("SESSION"));
dataStream = response.GetResponseStream();
for (int i = 0; i < response.Headers.Count; ++i)
Response.Write(response.Headers.Keys[i]+" : "+response.Headers[i]);
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Response.Write(responseFromServer);
reader.Close();
dataStream.Close();
response.Close();
Response.End();
}
protected void ClientPost()
{
//Create HTML Doc
StringBuilder createhtm = new StringBuilder();
createhtm.Append("<body onload=\"document.forms.SecurePass.submit()\">");
createhtm.Append("<div>");
createhtm.Append("<form action=\"" + (String)Session["PostURL"] + "\" method=\"post\" id=\"SecurePass\">");
createhtm.Append("<input type=\"text\" style=\"display:none\" name=\"" + (String)Session["userName"] + "\" " + "value=\"" + (String)Session["userNameValue"] + "\">");
createhtm.Append("<input type=\"password\" style=\"display:none\" name=\"" + (String)Session["password"] + "\" " + "value=\"" + (String)Session["passwordValue"] + "\">");
if ((String)Session["name1"] != "e" && (String)Session["value1"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name1"] + "\" " + "value=\"" + (String)Session["value1"] + "\">");
}
if ((String)Session["name2"] != "e" && (String)Session["value2"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name2"] + "\" " + "value=\"" + (String)Session["value2"] + "\">");
}
if ((String)Session["name3"] != "e" && (String)Session["value3"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name3"] + "\" " + "value=\"" + (String)Session["value3"] + "\">");
}
if ((String)Session["name4"] != "e" && (String)Session["value4"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name4"] + "\" " + "value=\"" + (String)Session["value4"] + "\">");
}
if ((String)Session["name5"] != "e" && (String)Session["value5"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name5"] + "\" " + "value=\"" + (String)Session["value5"] + "\">");
}
if ((String)Session["name6"] != "e" && (String)Session["value6"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name6"] + "\" " + "value=\"" + (String)Session["value6"] + "\">");
}
if ((String)Session["name7"] != "e" && (String)Session["value7"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name7"] + "\" " + "value=\"" + (String)Session["value7"] + "\">");
}
if ((String)Session["name8"] != "e" && (String)Session["value8"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name8"] + "\" " + "value=\"" + (String)Session["value8"] + "\">");
}
if ((String)Session["name9"] != "e" && (String)Session["value9"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name9"] + "\" " + "value=\"" + (String)Session["value9"] + "\">");
}
if ((String)Session["name10"] != "e" && (String)Session["value10"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name10"] + "\" " + "value=\"" + (String)Session["value10"] + "\">");
}
if ((String)Session["name11"] != "e" && (String)Session["value11"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name11"] + "\" " + "value=\"" + (String)Session["value11"] + "\">");
}
if ((String)Session["name12"] != "e" && (String)Session["value12"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name12"] + "\" " + "value=\"" + (String)Session["value12"] + "\">");
}
if ((String)Session["name13"] != "e" && (String)Session["value13"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name13"] + "\" " + "value=\"" + (String)Session["value13"] + "\">");
}
createhtm.Append("</form>");
createhtm.Append("</div>");
createhtm.Append("</body>");
Response.Write(createhtm);
}
protected void LoadSession()
{
//Response.Write(Request.Cookies["reauthen"].Value);
//Response.End();
String credential = service.DecryptData(Request.Cookies["reauthen"].Value);
String[] splitcredential = credential.Split('_');
Session["userName"] = "USER";
Session["password"] = "PASSWORD";
Session["userNameValue"] = splitcredential[1];
Session["passwordValue"] = splitcredential[2];
Session["PostURL"] = ConfigurationManager.AppSettings["postURL"];
if (ConfigurationManager.AppSettings["ShowSession"] == "true")
{
foreach (string key in Session.Keys)
{
Response.Write(key + "-" + Session[key] + "<br />");
}
Response.End();
}
}
}
}
The answer was easier than I expected, after pulling the headers from siteminder, I was able to pull the "set-cookie" header. Inside that header is a string starting with "SMSESSION=" if you create a cookie called SMSESSION with the value from the header (i.e. the encrypted value after "SMSESSION="). You will be able to redirect back to your protected resource logged in.
Be sure to pay close attention to the bottom of the encrypted string not to grab other values you don't want.
my code is as follows:
The parameter string may look a little confusing because I am calling other modules, but you should be able to get what you need out of the code:
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Services;
using System.Text;
using System.Net;
using System.IO;
using System.Collections;
using MFA.WebControls;
using System.Web.Security;
namespace SiteMinder_SiteMinder_Side
{
public partial class login : System.Web.UI.Page
{
//Config Values for Siteminder on this page are
// appsetting name "ClientOrServerPost" possible values "server"/"client"
// appsetting name "postURL" possible values "This is the url of the .fcc file on the webserver"
// appsetting name "ShowSession" possible values "true"/"false"
// appsettings name "serviceurl" possible values "the URL of the tdez webservice"
// appsettings name "CookieDomain" this is set in the admin "value should exist"
com.ezmultifactor.demoappliance.Service1 service = new com.ezmultifactor.demoappliance.Service1();
protected void Page_Load(object sender, EventArgs e)
{
LoadSession();
if (ConfigurationManager.AppSettings["ClientOrServerPost"] == "client")
{
ClientPost();
}
if (ConfigurationManager.AppSettings["ClientOrServerPost"] == "server")
{
ServerPost();
}
}
//Specifically for the Server Post
protected string createPramString()
{
String Params = String.Empty;
Params+=(String)Session["userName"]+"="+ Server.UrlEncode((String)Session["userNameValue"]);
Params+="&"+(String)Session["password"]+"="+ Server.UrlEncode((String)Session["passwordValue"]);
if ((String)Session["name1"] != "e" && (String)Session["value1"] != "e")
{
Params += "&" + (String)Session["name1"] + "=" + Server.UrlEncode((String)Session["value1"]);
}
if ((String)Session["name2"] != "e" && (String)Session["value2"] != "e")
{
Params += "&" + (String)Session["name2"] + "=" + Server.UrlEncode((String)Session["value2"]);
}
if ((String)Session["name3"] != "e" && (String)Session["value3"] != "e")
{
Params += "&" + (String)Session["name3"] + "=" + Server.UrlEncode((String)Session["value3"]);
}
if ((String)Session["name4"] != "e" && (String)Session["value4"] != "e")
{
Params += "&" + (String)Session["name4"] + "=" + Server.UrlEncode((String)Session["value4"]);
}
if ((String)Session["name5"] != "e" && (String)Session["value5"] != "e")
{
Params += "&" + (String)Session["name5"] + "=" + Server.UrlEncode((String)Session["value5"]);
}
if ((String)Session["name6"] != "e" && (String)Session["value6"] != "e")
{
Params += "&" + (String)Session["name6"] + "=" + Server.UrlEncode((String)Session["value6"]);
}
if ((String)Session["name7"] != "e" && (String)Session["value7"] != "e")
{
Params += "&" + (String)Session["name7"] + "=" + Server.UrlEncode((String)Session["value7"]);
}
if ((String)Session["name8"] != "e" && (String)Session["value8"] != "e")
{
Params += "&" + (String)Session["name8"] + "=" + Server.UrlEncode((String)Session["value8"]);
}
if ((String)Session["name9"] != "e" && (String)Session["value9"] != "e")
{
Params += "&" + (String)Session["name9"] + "=" + Server.UrlEncode((String)Session["value9"]);
}
if ((String)Session["name10"] != "e" && (String)Session["value10"] != "e")
{
Params += "&" + (String)Session["name10"] + "=" + Server.UrlEncode((String)Session["value10"]);
}
if ((String)Session["name11"] != "e" && (String)Session["value11"] != "e")
{
Params += "&" + (String)Session["name11"] + "=" + Server.UrlEncode((String)Session["value11"]);
}
if ((String)Session["name12"] != "e" && (String)Session["value12"] != "e")
{
Params += "&" + (String)Session["name12"] + "=" + Server.UrlEncode((String)Session["value12"]);
}
if ((String)Session["name13"] != "e" && (String)Session["value13"] != "e")
{
Params += "&" + (String)Session["name13"] + "=" + Server.UrlEncode((String)Session["value13"]);
}
return Params;
}
protected void ServerPost()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create((String)Session["PostURL"]);
request.Method = "POST";
string postData = createPramString();
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)";
request.AllowAutoRedirect = false;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
dataStream = response.GetResponseStream();
String[] headers = new String[response.Headers.Count];
//for (int i = 0; i < response.Headers.Count; ++i)
//{
// Response.Write("*" + response.Headers.Keys[i] + "~" + response.Headers[i]);
// headers[i] = response.Headers.Keys[i] + "*" + response.Headers[i];
//}
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
HttpCookie smsession = new HttpCookie("SMSESSION");
smsession.Value = ripOutSession((String)((HttpWebResponse)response).GetResponseHeader("Set-Cookie"),"sessionData");
smsession.Domain = ripOutSession((String)((HttpWebResponse)response).GetResponseHeader("Set-Cookie"), "domainData");
smsession.Path = "/";
smsession.Expires = Convert.ToDateTime(ripOutSession((String)((HttpWebResponse)response).GetResponseHeader("Set-Cookie"), "expireData"));
Response.SetCookie(smsession);
Response.Redirect((String)((HttpWebResponse)response).GetResponseHeader("Location"));
}
protected void ClientPost()
{
//Create HTML Doc
StringBuilder createhtm = new StringBuilder();
createhtm.Append("<body onload=\"document.forms.SecurePass.submit()\">");
createhtm.Append("<div>");
createhtm.Append("<form action=\"" + (String)Session["PostURL"] + "\" method=\"post\" id=\"SecurePass\">");
createhtm.Append("<input type=\"text\" style=\"display:none\" name=\"" + (String)Session["userName"] + "\" " + "value=\"" + (String)Session["userNameValue"] + "\">");
createhtm.Append("<input type=\"password\" style=\"display:none\" name=\"" + (String)Session["password"] + "\" " + "value=\"" + (String)Session["passwordValue"] + "\">");
if ((String)Session["name1"] != "e" && (String)Session["value1"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name1"] + "\" " + "value=\"" + (String)Session["value1"] + "\">");
}
if ((String)Session["name2"] != "e" && (String)Session["value2"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name2"] + "\" " + "value=\"" + (String)Session["value2"] + "\">");
}
if ((String)Session["name3"] != "e" && (String)Session["value3"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name3"] + "\" " + "value=\"" + (String)Session["value3"] + "\">");
}
if ((String)Session["name4"] != "e" && (String)Session["value4"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name4"] + "\" " + "value=\"" + (String)Session["value4"] + "\">");
}
if ((String)Session["name5"] != "e" && (String)Session["value5"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name5"] + "\" " + "value=\"" + (String)Session["value5"] + "\">");
}
if ((String)Session["name6"] != "e" && (String)Session["value6"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name6"] + "\" " + "value=\"" + (String)Session["value6"] + "\">");
}
if ((String)Session["name7"] != "e" && (String)Session["value7"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name7"] + "\" " + "value=\"" + (String)Session["value7"] + "\">");
}
if ((String)Session["name8"] != "e" && (String)Session["value8"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name8"] + "\" " + "value=\"" + (String)Session["value8"] + "\">");
}
if ((String)Session["name9"] != "e" && (String)Session["value9"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name9"] + "\" " + "value=\"" + (String)Session["value9"] + "\">");
}
if ((String)Session["name10"] != "e" && (String)Session["value10"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name10"] + "\" " + "value=\"" + (String)Session["value10"] + "\">");
}
if ((String)Session["name11"] != "e" && (String)Session["value11"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name11"] + "\" " + "value=\"" + (String)Session["value11"] + "\">");
}
if ((String)Session["name12"] != "e" && (String)Session["value12"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name12"] + "\" " + "value=\"" + (String)Session["value12"] + "\">");
}
if ((String)Session["name13"] != "e" && (String)Session["value13"] != "e")
{
createhtm.Append("<input type=\"hidden\" name=\"" + (String)Session["name13"] + "\" " + "value=\"" + (String)Session["value13"] + "\">");
}
createhtm.Append("</form>");
createhtm.Append("</div>");
createhtm.Append("</body>");
Response.Write(createhtm);
}
protected void LoadSession()
{
Session["userName"] = "USER";
Session["password"] = "PASSWORD";
Session["PostURL"] = ConfigurationManager.AppSettings["postURL"];
if (loginUserID() != "Empty")
{
LoadUserFromContext();
}
else
{
LoadUserDataFromCookie();
}
com.ezmultifactor.demoappliance.Service1 service = new com.ezmultifactor.demoappliance.Service1();
service.Url = ConfigurationManager.AppSettings["serviceurl"];
String userdelimpass = service.EncryptData("_" + Session["userNameValue"].ToString() + "_" + Session["passwordValue"].ToString() + "_Succsful");
HttpCookie reauthen = new HttpCookie("reauthen");
reauthen.Value = userdelimpass;
if (ConfigurationManager.AppSettings["CookieDomain"] != null)
{
reauthen.Domain = ConfigurationManager.AppSettings["CookieDomain"];
}
reauthen.Expires = DateTime.Now.AddMinutes(3.1);
Response.SetCookie(reauthen);
if (ConfigurationManager.AppSettings["ShowSession"] == "true")
{
foreach (string key in Session.Keys)
{
Response.Write(key + "-" + Session[key] + "<br />");
}
Response.End();
}
}
protected String ripOutSession(string validSessionHeader, string valuetoreturn)
{
String SMSESSION = validSessionHeader;
String SMSESSIONMinusSpace = SMSESSION.Replace(" ", "");
String[] SplitSession = SMSESSIONMinusSpace.Split(';');
String SaveSession = String.Empty;
String SaveDomain = String.Empty;
String SaveExpire = String.Empty;
String FinalResult = String.Empty;
for (int i = 0; i < SplitSession.Length; i++)
{
if (SplitSession[i].Contains("SMSESSION"))
{
SaveSession = SplitSession[i];
}
if (SplitSession[i].Contains("domain"))
{
SaveDomain = SplitSession[i].Replace("domain=", "");
}
if (SplitSession[i].Contains("expires"))
{
SaveExpire = SplitSession[i].Replace("expires=", "");
}
}
String[] splitSaveSession = SaveSession.Split(',');
for (int i = 0; i < splitSaveSession.Length; i++)
{
if (splitSaveSession[i].Contains("SMSESSION"))
{
SaveSession = splitSaveSession[i].Replace("SMSESSION=", "");
}
}
if (valuetoreturn == "sessionData")
{
FinalResult=SaveSession;
}
if (valuetoreturn == "domainData")
{
FinalResult=SaveDomain;
}
if (valuetoreturn == "expireData")
{
FinalResult = SaveExpire;
}
return FinalResult;
}
public static String loginUserID()
{
try
{
string userid = "";
ContextUser user = (ContextUser)HttpContext.Current.Session["currentuser"];
if (!string.IsNullOrEmpty(user.UserID.ToString()))
{
userid = user.UserID.ToString();
}
else { }
return userid;
}
catch
{
return "Empty";
}
}
public static String loginUP()
{
string up = String.Empty;
ContextUser user = (ContextUser)HttpContext.Current.Session["currentuser"];
if (!string.IsNullOrEmpty(user.Password.ToString()))
{
up = user.Password.ToString();
}
else { }
return up;
}
protected void LoadUserFromContext()
{
String loginValue = loginUP();
String RemoveDomain = loginUserID();
bool containDomain;
containDomain = (RemoveDomain.Contains("#"));
string[] UserSplit = RemoveDomain.Split(new Char[] { '#' });
if (containDomain == true)
{
RemoveDomain = UserSplit[0];
}
Session["userNameValue"] = RemoveDomain;
Session["passwordValue"] = loginValue;
}
protected void LoadUserDataFromCookie()
{
FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
String CookieDecryptedValueUserData = ticket.UserData.ToString();
String CookieDecryptedValueUserName = ticket.Name.ToString();
String RemoveDomain = CookieDecryptedValueUserName;
bool containDomain;
containDomain = (RemoveDomain.Contains("#"));
string[] UserSplit = RemoveDomain.Split(new Char[] { '#' });
if (containDomain == true)
{
RemoveDomain = UserSplit[0];
}
Session["userNameValue"] = RemoveDomain;
Session["passwordValue"] = CookieDecryptedValueUserData;
}
}
}