WCF error: "This collection already contains an address with scheme http".
The explanation is that "WCF services hosted in IIS can have only one Base Address".
Easy fix:
Just add the following lines in the system.serviceModel section:
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://www.example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
Wednesday, March 11, 2009
Tuesday, February 17, 2009
Redirect a page URL in javascript
The following code will redirect a page from index.aspx to the root URL in javascript:
var u = 'http://www.mysite.com/';
if (self.parent.frames.length != 0) self.parent.location=u;
if (self.location != u) self.location=u;//
var u = 'http://www.mysite.com/';
if (self.parent.frames.length != 0) self.parent.location=u;
if (self.location != u) self.location=u;//
Monday, February 16, 2009
301 Redirect in ASP.NET / C# Code
If you want to redirect a URL on a permanent basis using ASP.NET and C# code as an alternative to using IIS 6 or IIS 7, you can append the code to the old ASP.NET page.
Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "http://www.newpagelocation.com/");
Response.End();
Hope this helps!
Response.Clear();
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location", "http://www.newpagelocation.com/");
Response.End();
Hope this helps!
Friday, January 23, 2009
File Access Error .IPX IPIX 360 FILES
If you encounter an error with the message "file access error" when serving IPIX files via a windows server and IIS it is likely that:
1) Your browser has no java support (in this case you will NOT see the IPIX logo)
2) Your IIS Server is not configured to serve these files:
i) Right click the website in IIS > Properties
ii) Select the HTTP headers button
iii) Add a new MIME type with a .IPX extension and MIME type of application/x-ipx
Hope this helps someone - it drove me mad for 2 hours!
Thursday, December 11, 2008
Paypal country code dropdown select html
I recently needed to build a paypal dropdown country list to pass to a PAYPAL checkout form, it took me a while to find the permitted values and build an HTML select list so I have included it here for anyone who may find it useful! View the source of this page to get the html code for the select box!
Wednesday, October 15, 2008
Convert Object Array To Dataset
Bind an Object Array to a dataset using the following code.
Code Snippet
using System;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace BusinessObject.Util
{
///
/// Utility Class for Object Arrays.
///
public class ObjectArray
{
private Object[] _objectArray;
public ObjectArray(Object[] objectArray)
{
this._objectArray = objectArray;
}
public DataSet ToDataSet()
{
DataSet ds = new DataSet();
XmlSerializer xmlSerializer =
new XmlSerializer(_objectArray.GetType());
StringWriter writer = new StringWriter();
xmlSerializer.Serialize(writer, _objectArray);
StringReader reader =
new StringReader(writer.ToString());
ds.ReadXml(reader);
return ds;
}
}
}
How to use the code:
Person[] personList;
personList = Course.GetPersonList();
ObjectArray objectArray = new ObjectArray(personList);Create a DataSet and convert your ObjectArray to a DataSet using the method:
DataSet ds = new DataSet();
ds = objectArray.ToDataSet();
Reference Taken From
http://tom.gilki.org/programming/net/Utils/ObjectArrayDataSet/index.shtml
This entry was posted on February 21, 2007 at 9:44 am and is filed under .NET 1.1.
Code Snippet
using System;
using System.Data;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace BusinessObject.Util
{
///
/// Utility Class for Object Arrays.
///
public class ObjectArray
{
private Object[] _objectArray;
public ObjectArray(Object[] objectArray)
{
this._objectArray = objectArray;
}
public DataSet ToDataSet()
{
DataSet ds = new DataSet();
XmlSerializer xmlSerializer =
new XmlSerializer(_objectArray.GetType());
StringWriter writer = new StringWriter();
xmlSerializer.Serialize(writer, _objectArray);
StringReader reader =
new StringReader(writer.ToString());
ds.ReadXml(reader);
return ds;
}
}
}
How to use the code:
Person[] personList;
personList = Course.GetPersonList();
ObjectArray objectArray = new ObjectArray(personList);Create a DataSet and convert your ObjectArray to a DataSet using the method:
DataSet ds = new DataSet();
ds = objectArray.ToDataSet();
Reference Taken From
http://tom.gilki.org/programming/net/Utils/ObjectArrayDataSet/index.shtml
This entry was posted on February 21, 2007 at 9:44 am and is filed under .NET 1.1.
Thursday, September 11, 2008
Optimising Images for Web Using c#
Useful function to optimise images for web using c#
public void OptimizeImage(string lcFilename, decimal widthRequired)
{
System.Drawing.Image originalimg = System.Drawing.Image.FromFile(lcFilename);
decimal _percentNeeded;
_percentNeeded = Convert.ToDecimal(widthRequired) / originalimg.Width;
Int32 lnWidth = Convert.ToInt32(widthRequired);
Int32 lnHeight = Convert.ToInt32(originalimg.Height * _percentNeeded);
System.Drawing.Bitmap bmpOut = null;
System.Drawing.Bitmap loBMP = new System.Drawing.Bitmap(lcFilename);
System.Drawing.Imaging.ImageFormat loFormat = loBMP.RawFormat;
decimal lnRatio;
int lnNewWidth = 0;
int lnNewHeight = 0;
if (loBMP.Width > loBMP.Height)
{
lnRatio = (decimal)lnWidth / loBMP.Width;
lnNewWidth = lnWidth;
decimal lnTemp = loBMP.Height * lnRatio;
lnNewHeight = (int)lnTemp;
}
else
{
lnRatio = (decimal)lnHeight / loBMP.Height;
lnNewHeight = lnHeight;
decimal lnTemp = loBMP.Width * lnRatio;
lnNewWidth = (int)lnTemp;
}
bmpOut = new System.Drawing.Bitmap(lnNewWidth, lnNewHeight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
string _tmpFile = System.Configuration.ConfigurationManager.AppSettings["ContentLocationRoot"] + "tmp.jpg";
bmpOut.Save(_tmpFile, System.Drawing.Imaging.ImageFormat.Jpeg);
loBMP.Dispose();
originalimg.Dispose();
System.IO.File.Delete(lcFilename);
System.IO.File.Copy(_tmpFile, lcFilename);
System.IO.File.Delete(_tmpFile);
}
public void OptimizeImage(string lcFilename, decimal widthRequired)
{
System.Drawing.Image originalimg = System.Drawing.Image.FromFile(lcFilename);
decimal _percentNeeded;
_percentNeeded = Convert.ToDecimal(widthRequired) / originalimg.Width;
Int32 lnWidth = Convert.ToInt32(widthRequired);
Int32 lnHeight = Convert.ToInt32(originalimg.Height * _percentNeeded);
System.Drawing.Bitmap bmpOut = null;
System.Drawing.Bitmap loBMP = new System.Drawing.Bitmap(lcFilename);
System.Drawing.Imaging.ImageFormat loFormat = loBMP.RawFormat;
decimal lnRatio;
int lnNewWidth = 0;
int lnNewHeight = 0;
if (loBMP.Width > loBMP.Height)
{
lnRatio = (decimal)lnWidth / loBMP.Width;
lnNewWidth = lnWidth;
decimal lnTemp = loBMP.Height * lnRatio;
lnNewHeight = (int)lnTemp;
}
else
{
lnRatio = (decimal)lnHeight / loBMP.Height;
lnNewHeight = lnHeight;
decimal lnTemp = loBMP.Width * lnRatio;
lnNewWidth = (int)lnTemp;
}
bmpOut = new System.Drawing.Bitmap(lnNewWidth, lnNewHeight);
System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmpOut);
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, lnNewWidth, lnNewHeight);
g.DrawImage(loBMP, 0, 0, lnNewWidth, lnNewHeight);
string _tmpFile = System.Configuration.ConfigurationManager.AppSettings["ContentLocationRoot"] + "tmp.jpg";
bmpOut.Save(_tmpFile, System.Drawing.Imaging.ImageFormat.Jpeg);
loBMP.Dispose();
originalimg.Dispose();
System.IO.File.Delete(lcFilename);
System.IO.File.Copy(_tmpFile, lcFilename);
System.IO.File.Delete(_tmpFile);
}
Subscribe to:
Posts (Atom)