Sunday, April 22, 2012

Allow WCF multiple Binding on IIS

IIS supports specifying multiple IIS bindings per site. A WCF service hosted under a site allows binding to only one baseAddress per scheme.
I want to host service with multiple binding without custom factories.
http://seesaudi.com, http://seesaudimor.com

I found solution:
Solution in .Net 3.5:
Set the baseAddressPrefix to one of the addresses:


        <system.serviceModel>
        <serviceHostingEnvironment>
        <baseAddressPrefixFilters>
                <add prefix="http://seesaudi.com"/>    
        </baseAddressPrefixFilters>
        </serviceHostingEnvironment>
        </system.serviceModel>

  1. Set the endpoints in your web.config file to be absolute URIs:

  2.    <services>
          <service>
            <endpoint address="http://seesaudi.com/Service1.svc/e1"  Binding="..." Contract="..." />
           <endpoint address="http://seesaudimor.com/Service1.svc/e2"  Binding="..." Contract="..." />
          </service>
       </services>
Solution in .Net 4.0: 
  In order to enable multiple site binding, you need to set multipleSiteBindingEnabled to true in your application.

   <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />  

Thursday, April 19, 2012

Silverlight Designer Error

Silverlight Problem in Design Mode:

When Created Control in Silverlight I found error in design mode:


System.Reflection.TargetInvocationException

[Async_ExceptionOccurred]Arguments: Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See http://go.microsoft.com/fwlink/?linkid=106663&Version=4.0.50401.0&File=System.dll&Key=Async_ExceptionOccurred


After many invesigation I discovered I used HtmlPage object (Need browser to execute this line of code).
To fix this didn't execute Html object in design mode example:


if (!DesignerProperties.IsInDesignTool)
{
var height = HtmlPage.Document.Body.GetProperty("clientHeight");
var width = HtmlPage.Document.Body.GetProperty("clientWidth");
this.LayoutRoot.Width = double.Parse(width.ToString());
this.LayoutRoot.Height = double.Parse(height.ToString());
}

Sunday, March 25, 2012

System Center Service Manager 2012 Arabic Portal

It is a second time I worked in arabization of SCM Portal. It is easier than previous version because it is built in silver-light and separate UI layer and business layer.

Below video of SCM arabization:

Wednesday, May 18, 2011

An ASP.NET HttpModule to set the current culture to the user’s locale

My web application needs to display user information depend on its default culture.


I created an ASP.NET module:





using System;
using System.Globalization;
using System.Threading;
using System.Web;
namespace Gold.Translate
{
public class UserLocaleModule : IHttpModule
{
public void Init(HttpApplication httpApplication)
{
httpApplication.BeginRequest += (sender, eventArgs) =>
{
var app = sender as HttpApplication;
if (app == null)
{
throw new ApplicationException("Sender is null or not an HttpApplication");
}
var request = app.Context.Request;
if (request.UserLanguages == null request.UserLanguages.Length == 0) return;

var language = request.UserLanguages[0];
if (language == null) return;

try
{
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
}
catch
{}
};
}

public void Dispose()
{

}
}
}

Configuration in web.config for classic mode:








<httpModules runAllManagedModulesForAllRequests="true">
<add name="UserLocale" type="Gold.Translate.UserLocaleModule, Gold.Translate" />
</httpModules>


Configuration in web.config for integration mode:








<modules runAllManagedModulesForAllRequests="true">
<add name="UserLocale" type="Gold.Translate.UserLocaleModule, Gold.Translate" />
</modules>



Migration Issues with IIS 7

When you migrated from IIS 6 to IIS 7 you must take care of needed changes. I fiund 2 good Urls tell you about all issues need to take care of it:

http://help.godaddy.com/article/4162

http://world.episerver.com/Documentation/Items/Tech-Notes/EPiServer-CMS-5/EPiServer-CMS-5-R2-SP1/Changes-Between-IIS6-and-IIS7/

Thursday, April 28, 2011

Regular expressions

Sometimes I required to do some tasks using regular expression. In this post I decided to collect my regular expressions:

First regular expression is to find images in the html and replace its src url:







static string ReplaceTag(string HTMLBody, string srcPath, string newPath)
{
Regex reImg = new Regex(@"]*>", RegexOptions.IgnoreCase);
Regex reHeight = new Regex(@"height=(?:(['""])(?(?:(?!\1).)*)\1(?[^\s>]+))", RegexOptions.IgnoreCase RegexOptions.Singleline);
Regex reWidth = new Regex(@"width=(?:(['""])(?(?:(?!\1).)*)\1(?[^\s>]+))", RegexOptions.IgnoreCase RegexOptions.Singleline);
Regex reSrc = new Regex(@"src=(?:(['""])(?(?:(?!\1).)*)\1(?[^\s>]+))", RegexOptions.IgnoreCase RegexOptions.Singleline);
string tmpHTMLBody = HTMLBody;
MatchCollection mc = reImg.Matches(HTMLBody);
foreach (Match mImg in mc)
{
Console.WriteLine(" img tag: {0}", mImg.Groups[0].Value);
string tmpImgTag = string.Empty;
string tmpOldImgSrc = string.Empty;
string tmpNewImgSrc = string.Empty;
tmpImgTag = mImg.Groups[0].Value;

if (reHeight.IsMatch(mImg.Groups[0].Value))
{
Match mHeight = reHeight.Match(mImg.Groups[0].Value);
Console.WriteLine(" height is: {0}", mHeight.Groups["height"].Value);
}
if (reWidth.IsMatch(mImg.Groups[0].Value))
{
Match mWidth = reWidth.Match(mImg.Groups[0].Value);
Console.WriteLine(" width is: {0}", mWidth.Groups["width"].Value);
}
if (reHeight.IsMatch(mImg.Groups[0].Value))
{
Match mSrc = reSrc.Match(mImg.Groups[0].Value);
tmpOldImgSrc = mSrc.Groups["src"].Value;
tmpNewImgSrc = tmpOldImgSrc.ToLower().Replace(srcPath.ToLower(), newPath.ToLower());
tmpHTMLBody = tmpHTMLBody.ToLower().Replace(tmpOldImgSrc.ToLower(), tmpNewImgSrc.ToLower());
Console.WriteLine(" src is: {0}", mSrc.Groups["src"].Value);
}
}
return tmpHTMLBody;
}

This Regular Expression to Clean Word to Html remove word classes and attributes:







static internal string CleanWordHtml(string html)
{
// start by completely removing all unwanted tags
html = Regex.Replace(html, @"<[/]?(fonth1h2h3h4h5h6bspanxmldelins[ovwxp]:\w+)[^>]*?>", "", RegexOptions.IgnoreCase);
// then run another pass over the html (twice), removing unwanted attributes
html = Regex.Replace(html, @"<([^>]*)(?:classlangstylesizeface[ovwxp]:\w+)=(?:'[^']*'""[^""]*""[^\s>]+)([^>]*)>", "<$1$2>", RegexOptions.IgnoreCase);
html = Regex.Replace(html, @"<([^>]*)(?:classlangstylesizeface[ovwxp]:\w+)=(?:'[^']*'""[^""]*""[^\s>]+)([^>]*)>", "<$1$2>", RegexOptions.IgnoreCase);
return html;
}

This Regular Expression to remove tags from Html:







static internal string StripHtml(string html, bool allowHarmlessTags)
{
if (html == null html == string.Empty)
return string.Empty;

if (allowHarmlessTags)
return System.Text.RegularExpressions.Regex.Replace(html, "", string.Empty);

string strippedHtml = System.Text.RegularExpressions.Regex.Replace(html, "<[^>]*>", string.Empty);
strippedHtml = HttpUtility.HtmlDecode(strippedHtml);
return strippedHtml;
}


Check that a string contains Arabic Characters using C#:





static internal bool hasArabic(string text)
{
Regex regex = new Regex(
"\\p{IsArabic}");
return regex.IsMatch(text);
}

Friday, April 8, 2011

How to run 32-bit UDL file on a 64-bit Operating System

Once we create an UDL File and run it on 64 Bit OS, it will list down all the 64 bit OLE DB providers installed on the machine. The reason behind for this is simple.
When you double click on a UDL file on a 64 bit machine, it’ll enumerate only the 64 bit OLE DB Providers and if we have the 32 bit Ole DB providers installed, we will not be able to find that in the enumerated list.
Create a udl file with the name test.udl under the path, C:\.
When we have created a UDL file on a 64 bit machine and try to open it, the following:
"C:\Program Files\Common Files\System\Ole DB\oledb32.dll",OpenDSLFile C:\test.udl Command will be called through C:\windows\system32\rundll32.exe.
Here both Oledb32.dll and rundll32.exe are 64 bit and will not enumerate the 32bit Dlls.
How to run the UDL which lists down the 32bit Dlls?
We can find the 32bit version of Oledb32.dll under the path:
C:\Program Files (x86)\Common Files\System\Ole DB
and 32 bit version of rundll32.exe under the path:
C:\WINDOWS\SysWOW64.
We’ll need to execute the command below from a command line or Start/Run :
C:\Windows\syswow64\rundll32.exe "C:\Program Files (x86)\Common Files\System\Ole DB\oledb32.dll",OpenDSLFile C:\test.udl
Check the paths of rundll32.exe and oledb32.dll while running this command