SQL


A ASP.NET web page goes blank if you inject the javascript alert(); function using the Response.Write from the the code behind.

Here is the fix for it.

private void ShowMessage(string message)

{

StringBuilder scriptBuilder = new StringBuilder("<script language=’javascript’>function window.onload(){");

scriptBuilder.Append("alert(‘" + message + "’);");

scriptBuilder.Append("}</script>");

if (!ClientScript.IsClientScriptBlockRegistered("MyMessage"))

{

ClientScript.RegisterClientScriptBlock(this.GetType(), "MyMessage", scriptBuilder.ToString());

}

}

Advertisements

private void UpdateConnectionString(string ConfigPath)

{

XmlDocument xmlDocument = new XmlDocument();

xmlDocument.Load(ConfigPath);

XmlNode parentNode = xmlDocument.DocumentElement;

if (parentNode.Name == "connectionStrings")

{

foreach (XmlNode childNode in parentNode.ChildNodes)

{

if (childNode.Name == "add" && childNode.Attributes["name"].Value=="MySqlConnection")

{

string sqlConnectionString = childNode.Attributes["connectionString"].Value;

SqlConnectionStringBuilder sqlBuilder = new SqlConnectionStringBuilder(sqlConnectionString);

sqlBuilder.InitialCatalog = "yourDatabaseName";

sqlBuilder.IntegratedSecurity = true;

sqlBuilder.Password = "";

//Change any other attributes using the sqlBuilder object

childNode.Attributes["connectionString"].Value = sqlBuilder.ConnectionString;

}

}

}

xmlDocument.Save(ConfigPath);

}

private string GetOpenPort()

{

int PortStartIndex = 1000;

int PortEndIndex = 2000;

IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();

IPEndPoint[] tcpEndPoints = properties.GetActiveTcpListeners();

List<int> usedPorts = tcpEndPoints.Select(p => p.Port).ToList<int>();

int unusedPort = 0;

for (int port = PortStartIndex; port < PortEndIndex; port++)

{

if (!usedPorts.Contains(port))

{

unusedPort = port;

break;

}

}

return unusedPort.ToString();

}

private bool PublishWebSite(string SiteName)

{

try

{

string siteName = "YourSiteName";

string applicationPoolName = "ASP.NET v4.0 Classic";

string virtualDirectoryPath = "/";

//Path to the folder of the published code

string virtualDirectoryPhysicalPath = "yourDirectoryPath";

//IP address of current machine where the site is to be published

string ipAddress = "IpAddressOfServer";

//Port to be assigned to the site

string tcpPort = "1109";

//Site name that appears in the URL

string hostHeader = string.Format("www.{0}", siteName);

string applicationPath = "/";

long highestId = 1;

using (ServerManager serverManager = new ServerManager())

{

Site site = serverManager.Sites[siteName];

if (site != null)

{

return false;

}

ApplicationPool appPool = serverManager.ApplicationPools[applicationPoolName];

if (appPool == null)

{

throw new Exception(String.Format("Application Pool: {0} does not exist.", applicationPoolName));

}

highestId = serverManager.Sites.Max(i => i.Id);

highestId++;

site = serverManager.Sites.CreateElement();

site.SetAttributeValue("name", siteName);

site.Id = highestId;

site.Bindings.Clear();

//Assign the IP address , Port and site URL

string bind = ipAddress + ":" + tcpPort + ":" + hostHeader;

Binding binding = site.Bindings.CreateElement();

binding.Protocol = "http";

binding.BindingInformation = bind;

site.Bindings.Add(binding);

Application application = site.Applications.CreateElement();

application.Path = applicationPath;

application.ApplicationPoolName = applicationPoolName;

//Create a virtual directory in IIS

VirtualDirectory vdir = application.VirtualDirectories.CreateElement();

vdir.Path = virtualDirectoryPath;

//Set the physical path of the folder

vdir.PhysicalPath = virtualDirectoryPhysicalPath;

application.VirtualDirectories.Add(vdir);

site.Applications.Add(application);

//Add this new site to the pool of sites in IIS

serverManager.Sites.Add(site);

serverManager.CommitChanges();

}

return true;

}

catch (Exception)

{

return false;

}

}

private bool CopyFolderContents(string SourcePath, string DestinationPath)

{

SourcePath = SourcePath.EndsWith(@"\") ? SourcePath : SourcePath + @"\";

DestinationPath = DestinationPath.EndsWith(@"\") ? DestinationPath : DestinationPath + @"\";

try

{

if (Directory.Exists(SourcePath))

{

if (Directory.Exists(DestinationPath) == false)

{

Directory.CreateDirectory(DestinationPath);

}

foreach (string files in Directory.GetFiles(SourcePath))

{

FileInfo fileInfo = new FileInfo(files);

fileInfo.CopyTo(string.Format(@"{0}\{1}", DestinationPath, fileInfo.Name), true);

}

foreach (string drs in Directory.GetDirectories(SourcePath))

{

DirectoryInfo directoryInfo = new DirectoryInfo(drs);

if (CopyFolderContents(drs, DestinationPath + directoryInfo.Name) == false)

{

return false;

}

}

}

return true;

}

catch (Exception ex)

{

return false;

}

}

I encourage anyone to try to solve it using only its logic skills, since it is a very rewarding experience, especially when its creator declared that “98% of the world population would not be able to solve it”

The Riddle

  1. In a town, there are five houses, each painted with a different color.
  2. In every house leaves a person of different nationality.
  3. Each homeowner drink a different beverage, smokes a different brand of cigar, and owns a different type of pet.

The Question

Who owns the fishes?

Hints

  1. The Brit lives in a red house.
  2. The Swede keeps dogs as pets.
  3. The Dane drinks tea.
  4. The Green house is next to, and on the left of the White house.
  5. The owner of the Green house drinks coffee.
  6. The person who smokes Pall Mall rears birds.
  7. The owner of the Yellow house smokes Dunhill.
  8. The man living in the center house drinks milk.
  9. The Norwegian lives in the first house.
  10. The man who smokes Blends lives next to the one who keeps cats.
  11. The man who keeps horses lives next to the man who smokes Dunhill.
  12. The man who smokes Blue Master drinks beer.
  13. The German smokes Prince.
  14. The Norwegian lives next to the blue house.
  15. The man who smokes Blends has a neighbor who drinks water.

NOTE : The main point of the Einstein’s Riddle is that 98% of human beings are unable to hold in memory more than 9 information units simultaneously ( whatever they could be ). Indeed, try to solve it using only your brain, and NOT using any other means ( such as paper, pencil, computers, e t. c.). I bet you will at least making significant efforts ( if not reject to solve it at all )…

int x = 200;

int y = 300;

Response.Write("Before swap ");

Response.Write("x=" + x + ",y=" + y);

Response.Write("

Next Page »