Wednesday, March 9, 2011

IIS URL Rewrite Module - Redirect HTTP to HTTPS with IIS 7

Using IIS URL Rewrite Module, Web administrators can easily set up rules to define URL rewriting behavior based on HTTP headers, HTTP response or request headers, IIS server variables, and programmatic rules. Here the main purpose is to implement URLs that are easier for users to remember and easier for search engines to find.

In addition, we can define rules to force SSL on selected pages of a Website which is hosted in IIS 7. First of all we need to install Microsoft URL Rewrite Module in IIs. Then we need to install SSL certificate, create HTTPS bindings to our IIS Web site and assign the certificate. Then select our Web site under Sites node and make sure "Require SSL" is NOT checked under SSL Settings.

After that we have to add following config section to the web.config file in the Web site root directory.
















In here a rewrite rule is defined by specifying a pattern to use for matching the URL string and an action to perform if a pattern is matched. In addition an optional condition is also specified which will be checked in the matching step.

Thanks Carlos Redondo for your suggestion!

Monday, March 7, 2011

Skill Based Search in Lync 2010

As we search in Lync for people in the organization by name, we can configure it to enable search for people by skill set. When I was searching for ways on extending Lync Client, I came across this built-in feature called “Skill Based Search” on Lync 2010. When we configure Lync Skill Search, users can search SharePoint Server 2010 My Site pages for names, keywords, or specific skills. We can also add a link at the bottom of the Lync search results window that opens the search results in SharePoint.

(My Sites in SharePoint 2010 is a personal site for individual users that gives a central location to manage and store documents, content, newsfeeds, links, and contacts. Also My Site contains a section defining and sharing profile information and content with other users in the organization. My Sites give users rich social networking and collaboration features enabling easily share information about themselves and their work. This article describes how to set up My Sites in Microsoft SharePoint Server 2010.)

In order to configure Lync 2010 Skill Search, "New-CsClientPolicy" or "Set-CsClientPolicy" commands are used with "SPSearchExternalURL" and "SPSearchInternalURL" parameters to configure a Client Policy. Then using "Grant-CsClientPolicy" we can assign the new policy/policies to users.

Also using "SPSearchCenterExternalURL" and "SPSearchCenterInternalURL" parameters we can add a link to the bottom of the Skill Search results that says, “View results in SharePoint…”. Users can use this link to refine search results by using the advanced search capabilities of SharePoint Server.

Link
Commands to run in Power Shell to enable the Skill based search URLs;
Set-CSClientPolicy -SPSearchInternalURL http://<server>/_vti_bin/search.asmx
Set-CSClientPolicy -SPSearchExternalURL http://<server>/_vti_bin/search.asmx
Set-CSClientPolicy -SPSearchCenterInternalURL http://<server>/SearchCenter/Pages/PeopleResults.aspx
Set-CSClientPolicy -SPSearchCenterExternalURL http://<server>/SearchCenter/Pages/PeopleResults.aspx

Parameters;
SPSearchCenterExternalURL: This is for users logging on from outside the organization’s firewall. This URL will appear at the bottom of keyword search results giving the user the opportunity to conduct searches using the search capabilities of SharePoint.
SPSearchCenterInternalURL: URL for users logging on from inside the organization’s firewall to conduct searches using the search capabilities of SharePoint.
SPSearchExternalURL: Lync 2010 will use this SharePoint site when a user who has accessed the system from outside the organization’s firewall conducts a keyword search.
SPSearchInternalURL: Will use the SharePoint site located at this URL when a user who has logged on from inside the organization’s firewall conducts a keyword search.

For more information on Enabling Skill Search in Lync 2010;
http://blogs.catapultsystems.com/tharrington/archive/2010/11/15/enabling-skill-search-in-lync-2010.aspx
For more information on getting this to work externally via Threat Management Gateway;
http://techblurt.com/2011/02/22/lync-2010-people-search-with-sharepoint-2010-and-tmg/
For more information on Lync 2010 Integration;
http://technet.microsoft.com/en-us/library/gg398806.aspx

Friday, February 4, 2011

How to Configure SSL on Particular Pages of an IIS 7 Website

Today I wanted to force SSL on selected pages of a Website which is hosted in IIS 7. I could find lot of articles in the Web describing how to configure SSL for the whole website. But I needed it for few specific pages only. This is the way finally I achieved my goal.

Using Server Certificates feature of the IIS server install my certificate.
Create a SSL Binding for my Web site and make sure all the pages are accessible via both HTTP and HTTPS.

Then in order to force SSL on selected pages I used following method on Page_Load event of those pages. In here I used Request.ServerVariables collection to see if the protocol being used is HTTP or HTTPS.


protected void Page_Load(object sender, EventArgs e)
{
// Redirect to the corresponding secure page.
RedirectToSecurePage();
}




///
/// Redirect to the corresponding secure page.
/// Assumption: IIS web site is configured in port 80.
///

public void RedirectToSecurePage()
{
var httpsMode = string.Empty;
var serverName = string.Empty;
var url = string.Empty;

for (var i = 0; i < Request.ServerVariables.Keys.Count; i++)
{
var key = Request.ServerVariables.Keys[i];
if (key.Equals("HTTPS"))
{
httpsMode = Request.ServerVariables[key];
}
else if (key.Equals("SERVER_NAME"))
{
serverName = Request.ServerVariables[key];
}
else if (key.Equals("URL"))
{
url = Request.ServerVariables[key];
}
}
if (httpsMode.Equals("off"))
{
Response.Redirect(string.Concat("https://", serverName, url));
}
}


So when each page is browsed, the code that is contained in the Page_Load event detects if HTTP is used. If HTTP is used, the browser will be redirected to the same page by using HTTPS.

Comments are really appreciated on how to handle this scenario in another (better) way...


Thursday, January 20, 2011

ClickOnce Deployment

In order to use ClickOnce deployment, first of all we have to publish our desktop application to a Web site, FTP server, or to a file path. Then we can use a client script in our Web application to download and run the published desktop application.

1. Go to the Properties of the Windows/WPF project. In the Publish tab set the publish location. Here I have published my application to an IIS Web site.

2. Right click on the Windows/WPF project and select Publish. Follow the publish wizard. After successful Publish, if you go to the physical path of the Web site, published content can be seen as follows.

Then we can register a JavaScript in our ASP.NET Web application to download the desktop application as follows.

Method 1 : window.open
 
///
/// Register client script to launch desktop application.
/// Method 1 : window.open
///

private void LaunchApplicationMethod1()
{
string clientApplicationURL = "http://localhost:82/MyCliclOnceApp.application";

System.Text.StringBuilder jScript = new System.Text.StringBuilder();

jScript.Append("");

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LaunchClientApplicationBlock", jScript.ToString());
}


Method 2 : window.location.href

///
/// Register client script to launch desktop application.
/// Method 2 : window.location.href
///

private void LaunchApplicationMethod2()
{
string clientApplicationURL = "http://localhost:82/MyCliclOnceApp.application";

System.Text.StringBuilder jScript = new System.Text.StringBuilder();

jScript.Append("");

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LaunchClientApplicationBlock", jScript.ToString());
}


As you can notice I have passed two arguments to the desktop application through launching client script. They can be consumed in the desktop application as follows.

  
private void Application_Startup(object sender, StartupEventArgs e)
{
try
{
int? clientId = null;
int? clientType = null;

if (ApplicationDeployment.IsNetworkDeployed)
{
// Loaded from the web?
if (ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
string value1 = HttpUtility.ParseQueryString(queryString)["ClientId"];

queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
string value2 = HttpUtility.ParseQueryString(queryString)["ClientType"];

try
{
clientId = int.Parse(value1);
clientType = int.Parse(value2);
}
catch
{ }
}
}
}
catch (Exception ex)
{ }
}


ClickOnce Deployment – Add Custom Desktop Icon for the Shortcut

An application deploying by ClickOnce deployment can be configured to available online only or to available through the start menu. By selecting "The application is available offline as well (launchable from Start menu)" option from the Project Properties -> Publish Tab, it can make available in offline mode as well.

In order to create a shortcut on the user’s desktop for this application, we have to select “Create desktop shortcut” from the “Publish Options” dialog as shown in the following figure. (Publish Tab -> Options…)



This will create a shortcut on the user's desktop with a standard icon. Then to add a custom icon, go to the “Application” tab, browse and select the preferred icon.