schuirink.net
main destinations: home | the web & the world | out of here
Google

news headlines

News headlines collected from 498 newsfeeds.

weblogs.asp.net non-ms bloggers

url: http://weblogs.asp.net

Novos artigos no MSDN


Olá pessoal, já estão publicados meus 3 novos artigos para ajudar a comunidade.

- Windows Phone 7 - dados de OData  - http://msdn.microsoft.com/pt-br/library/hh972465.aspx

- Bing Maps no Windows Phone 7.5 - http://msdn.microsoft.com/pt-br/library/hh972467.aspx

- A importância e o uso do Data Annotation - http://msdn.microsoft.com/pt-br/library/jj129537

Bons estudos e sucesso.



Trends in HTML5 and mobile development - webinar recording


A couple of weeks ago I wrote a blog post inviting you all to our webinar we presented with Forrester Research. So thanks for everyone who attended and special thanks to Jefferey Hammond of Forrester who did an outstanding job in discussing the Open Web, Cloud computing and Mobility trends and presenting the new development challenges they bring and why organizations need to rethink their application development strategies. I wanted to bring to your attention the availability of the recorded video...(read more)

Configure Email notifications on SharePoint 2010 list


In this article I am going to demonstrate how you can configure email notification feature on SharePoint List. For the purpose of demonstration I chose the default tasks list that is coming with almost all default SharePoint sites. Tasks list have one column ?Assigned To?. When an item is created in the task list, I would like to send an email to the user to whom the task is assigned. The scenario is very simple and straight forward.

In order to perform certain action when an Item is created in a list, you can make use of Workflow. To understand more about workflows in SharePoint 2010, refer the link http://technet.microsoft.com/en-us/sharepoint/ff819861 .

So What I need to do is to create a list workflow that is associated with my Tasks list. The workflow should be initiated automatically whenever an item is added to the tasks list. I am going to use SharePoint Designer as the workflow authoring tool.

Open SharePoint designer and open the site where your tasks list resides. Click on File menu, then select Add Item from the Menu. Under the workflow section, select List Workflow

clip_image001

Now SharePoint designer will ask you to enter a name for your workflow. Also select a list to which the workflow will be applied. Since I am going to create a workflow on task list, I have selected it and for the purpose of this demonstration I have named the workflow as ?MyTaskFlow?. Click on create button once you are done.

clip_image003

SharePoint Designer will open the Workflow in the workflow editor. The default workflow screen will look similar to the following.

clip_image005

In our case the workflow is simple; we just need to add a step that will send email. In real life you may need to check certain condition, for e.g. if the task priority is high, then send email etc. When sending email, the workflow should access the data from the created item such as who created it and to whom it is assigned etc. You can add conditions and actions to workflow. In our case, it is just one action. Click on the Action Icon in the top and select send email.

clip_image006

When you click on Action icon, it will pop up all the available actions that you can choose from. There are many actions available and we need send an Email Action.

clip_image007

When you choose the Action, it will be inserted in the Step. Also you can simply type in the Step where underline is there to pick the right action/condition. This is another way of authoring if you don?t want to use mouse and menu to pick the actions/conditions. The default Send Email action will look similar to following.

clip_image008

Click on users link, it will bring Define email dialog. Here you need to select address, subject and a body for the email.

clip_image009

First you need to enter the To address. Click on the browser button next to To: text box. Here you can add a static email address or you can pick it from SharePoint objects. As our requirement is to send to the user in the Assigned To field, you have an option to pick this data from the current Item property. First select Workflow lookup for a user, click on the Add button.

 clip_image010

This will bring the lookup dialog to select the item and field. Also make sure you select return field as Email Address.

clip_image011

Click OK twice so the select users dialog will be closed. Now in the subject box, enter some text. You can even pick the data from current item such as showing the task title in the subject. In the body part, you need to tell the user ?the task is created for you at

 clip_image012

Click OK once you are done. Now you can see the start options for the workflow as follows.

clip_image013

Since I want the workflow to start automatically when an Item is created I selected the second option. Now I need to publish it. To publish the workflow, press on the publish button in the top.

clip_image014

Now when you go to your list, you will see the workflow is available under the list you configured the workflow, in our case under the Tasks list. From the browser, go to the tasks list, then open list tab.

clip_image016

On the right corner, you can see workflow settings link

clip_image017

Click on the Workflow Settings link, this will open the workflow settings for the tasks list and you can find our workflow is available in the list.

 

clip_image019

Now go and add a new list item and you will see the workflow will be executed automatically and will send email. Designing such business processes is simple and straight forward with SharePoint 2010 and SharePoint Designer. Without writing single line of code you can achieve your day to day business requirements.



"An error occurred when verifying security for the message." when executing .SaveChanges()


Hi,

I have just came across this exception when trying to execute the SaveChanges() method of my ServiceContext object in CRM 2011 (on-premise).

 

Exception:

"An unsecured or incorrectly secured fault was received from the other party. See the inner FaultException for the fault code and detail."

 

Inner Exception:

"An error occurred when verifying security for the message."

 

Unfortunately I couldn?t find so much useful information around about the InnerException, which I guess should be the first thing to search for. But, I did could find related info about the main Exception and realized that I was also having troubles to connect from my CRM Outlook client too. So, I suspected that it was something wrong with my machine but not the code, the code was right.

And that was true. The problem was my clock. As I have changed my time zone, time was not in synch with my CRM 2011 server.

 

Solution:

In my case, I just set up same time zone in my machine as the server is set up, adjusted the clock, F5 again and voila! SaveChanges() worked like a charm Smile

 

Hope it helps to save somebody else?s time,

PP [twitter: @pabloperalta]

UruIT Dynamix | Excellence in Dynamics CRM Nearshoring Services.



CI Deployments To IIS VIA MS Web Deploy 2.0


Now that I have my source code being checked into GitHub and have TeamCity doing automatic builds (and running tests), I thought it was about time to take the last big step and automatically deploy the latest version of an application to a live site (either for testing or just straight to production, it?s up to you) whenever a successful build has taken place.

The best resource I?ve found for deploying directly from TeamCity (note: the steps would be the same for any CI server) can be found in Troy Hunt?s excellent 5 part blog series here: http://www.troyhunt.com/2010/11/you-deploying-it-wrong-teamcity.html.  It is very comprehensive and well worth a read, but I had some issues configuring deployment permissions and wanted to detail them here in case it helps someone else down the road.

An Overview Of the CI Deployment Process

Here?s a basic idea of how to get started?if you?ve ever used the Visual Studio 2010 ?Publish? wizard then you are 1/2 way there.  If you have any questions on these steps, refer to the blog series mentioned above or Google with Bing for help.

  • Install Microsoft Web Deploy 2.0 from http://www.iis.net/download/webdeploy on the server you wish to publish to.
  • Setup Web.Config transformations for your desired build configurations (see http://msdn.microsoft.com/en-us/library/dd465318.aspx)
  • Inside Visual Studio, right click ?> properties on your Web project, and under Package/Publish Web setup the IIS Web Application name to match your IIS server
    • This is the virtual directory inside IIS that your deployment will be pushed to.  Set it up for each desired build configuration.
  • Setup Permissions on your IIS Server to allow web deployment from your CI agent or service account (detailed below).
  • Craft an MSBuild command that will build AND deploy your web application, and run it during your CI Server build process (also detailed below).

Deploying Via MSBuild

That last point requires a bit of explanation as it?s the crux of the problem (other than permissions, which I?ll get to later).  What we want MSBuild to do here is to build your project/solution using the desired build configuration (like Debug/Release) and then to use the MS Web Deploy service to push your auto-created deployment package to IIS.  Here?s an example of MSBuild parameters from Troy?s blog that will accomplish this:

/P:Configuration=%env.Configuration%
/P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=https://%env.TargetServer%/MsDeploy.axd
/P:AllowUntrustedCertificate=True
/P:MSDeployPublishMethod=WMSvc
/P:CreatePackageOnPublish=True
/P:UserName=AutoDeploy\Administrator
/P:Password=Passw0rd

Basically the above parameters use the provided env.Configuration (Debug/Release) to set the build configuration and then tell MSBulid to deploy using WMSvc (web management service) to the service url located at env.TargetServer (you can set the defaults on your CI server).

This is pretty handy, but I unfortunately for me (and maybe for you) there are two problems here:

#1: The user (AutoDeploy\Administrator) needs to be an admin on your IIS, and you need to have allowed Administrators to bypass rules in the ?Management Service Delegation? area of IIS (see ScottGu?s post here: http://weblogs.asp.net/scottgu/archive/2010/09/13/automating-deployment-with-microsoft-web-deploy.aspx).  For me, this is too much by itself.

#2: The username and password as passed in plain text through your configuration, as shown above. Not good.

The rest of this post will detail how to solve these issues, and in the end we will setup an service account that has non-admin access and which doesn?t require passing credentials manually.

Setting Up the Service Account

The first step is to create a non-admin service account that will be used on both your build server and IIS boxes. I?ll be using a no-login domain account called ?mydomain\builderservice?, but any account would work.

On your CI server (in my case, TeamCity), you?ll want to run your build agent as your new service account, as shown here:

image

Note you might also have to give this service access to certain files. For example, in TeamCity the build agent needs access to C:\TeamCity\buildAgent to do its work.

Changing the MSBuild Script to Run As ?Current User?

This part was fairly tricky since simply removing the UserName/Password parameters from the msbuild command will not work as expected.  Instead you must specify the AuthType to be NTLM (or it will default to Basic) and the UserName=[blank] so it will impersonate the current user.  The relevant parameters are /P:UserName= /P:AuthType=NTLM.  This makes the final MSBuild parameters:

/P:Configuration=%env.Configuration%
/P:DeployOnBuild=True 
/P:DeployTarget=MSDeployPublish 
/P:MsDeployServiceUrl=https://%env.TargetServer%/MsDeploy.axd
/P:AllowUntrustedCertificate=True 
/P:MsDeployPublishMethod=WMSvc 
/P:CreatePackageOnPublish=True 
/P:UserName= 
/P:AuthType=NTLM

Now that we have TeamCity running MSBuild with these parameters while running under a service account, we need to grant permission on the IIS server that has MS Deploy installed (%env.TargetServer%).

IIS Server Permission For Deployment

Your mileage may vary, but in order to get a successful web deployment from a non-administrator account, I had to perform the following steps, each of which I will explain in detail.

  1. Enable Windows Authentication for the Web Management Server (WMSvc)
  2. Grant Management Service Delegation rights at the Site level to the necessary providers
  3. Grant IIS Manager Permissions to your virtual application
  4. Grant file/folder permissions to the web directory

#1: Enable Windows Authentication for the Web Management Server (WMSvc)

In order to get the WMSvc to accept my build agent credentials, I had to enable Windows Authentication inside the IIS Management Service. You can do this either from the UI or Windows Registry as described in this stackoverflow post.  For convenience, here is the regex key (make sure to restart the WMSvc after making the change): ?reg add HKLM\Software\Microsoft\WebManagement\Server /v WindowsAuthenticationEnabled /t REG_DWORD /d 1?

#2: Grant Management Service Delegation rights at the Site level to the necessary providers

Next you must Delegate to your service account the rights to perform certain actions through the management service providers. If you forget any of these you will get a helpful error message saying that you don?t have rights to run a certain provider (ex: ?createApp?) so you?d then need to come back in and add those.  I needed the following providers: ?contentPath, iisApp, createApp, setAcl.?

To set a delegation rule go to your site root in IIS and under Management choose ?Management Service Delegation.?  Now choose ?Add Rule? in the upper-right and choose the ?Deploy Applications with Content? template (this has the best defaults) and then add in your desired providers. Mine looked like this:

image

Click ok, and now that the rule is defined you just have to select the newly created rule and choose ?Add User To Role.?  In the ensuing dialog enter the name of your service account and press OK.

image

#3: Grant IIS Manager Permissions to your virtual application

Now that you granted site-level provider access within the {userScope} path, you must give the account IIS permission on the site/application that you will be deploying to.  Choose your site and then under Management choose ?IIS Manager Permissions.?  Now click ?Allow User? and enter the account name again to grant access.

image

#4: Grant file/folder permissions to the web directory

This one is pretty obvious, but you still have to remember to give full control to your service account at the OS-folder level (ex: C:\inetpub\SiteName).  Right-click ?> Properties ?> Security ?> Edit, and then choose Add.  Now type in your service account one more time, grant it full control, and you are finished.

image

Celebrate!

That was certainly a lot of info, and I hope it makes someone?s deployment configuration easier.  Integrating your build, test, and deployments with a CI Server like TeamCity has many advantages, including the ability to handle ?deploy automatically only when all tests pass? and ?oops, deploy the version from last week? scenarios.

May all your Deployments be green.

image

Enjoy!



Windows Azure SDK for Node.js 0.5.4 Released


The Microsoft Windows Azure team has released the Windows Azure SDK for Node.js 0.5.4 which  will be using the Node.js 0.6.17 and iisnode 0.1.19. The Node.js 0.6.17 contains a security fix against the HTTP Server Security Vulnerability detected by recently. It would be recommended to upgrade to the new version of Azure SDK for Node.js if you have already deployed any Node.js app to Windows Azure which will provide better security. The iisnode 0.1.19 provides iisnode.yml file instead of XML based configurations which can be use for setting up all iisnode settings. You can download the Windows Azure SDK for Node.js 0.5.4 from here.



Understanding asynchronous programming in ASP.NET


I recently posted about asynchronous programing patterns in .NET. Like .net framework, ASP.NET has supported asynchronous programming since 1.x. C# and VB.NET introduced the new async and await keywords in the upcoming Visual Studio 11. This is also supported in the upcoming ASP.NET 4.5. On the other hand, there is currently an open source project from the ASP.NET team called SignalR. It uses synchronous programming model to support long running comet-like request in ASP.NET. SigalR can be used in ASP.NET 4.0 today. The purpose of this post is to talk about a little bit of history so that we can put new projects/features in perspective.

In asynchronous programming, the callee will create another thread to handle the execution and return immediately the the caller. The caller can go on with another task, or wait, join, or be called back from the callee. So one may ask what does asynchronous programming have to do with ASP.NET. Which is the caller and which is the callee?

It turns out that the caller is ASP.NET and the callee is the asynchronous HttpHandler. When IIS calls into ASP.NET, ASP.NET immediately posts the request to the CLR ThreadPool and returns a pending status to IIS. This frees the IIS thread so that it can be used to handle static contents. In the request is handled by an IHttpHandler in ASP.NET, a thread will handle the entire life cycle of the request. If the request is handled by an IHttpAsyncHandler, ASP.NET will call the BeginProcessRequest method of the handler and return the thread to the thread pool as soon as the method exists. If the handler simply creates another thread in the BeginProcessRequest method and immediately returns, there is really no benefits since we are simply replace one thread with another. If the handler make an asynchronous call to another class that is IO blocking and immediately returns, there is real benefit because the ASP.NET thread is no longer blocked by the IO and can be returned to the thread-pool to server other requests. Even though there is not a thread associated with the request, the connection remains open until the call-back delegate passed into the BeginProcessRequest method is called. This powerful method allows an asynchronous ASP.NET application to handle far more requests than synchronous application if IO blocking is a concern. On the other hand, it is possible for an application to keep a connection open for a long time with allocating a thread, and allocates thread only on events. That is why SignalR can work today. What is the cost to keep those connections open? The TCP/IP stack needs to keep connection info. IIS and ASP.NET also need to keep the context info. That?s say we need in average 5kB to keep a connection open. Then 1GB of memory would allow us to keep 200,000 connections open. This is unusually large number for synchronous asp.net applications. That is why SignalR implementations often configure much larger number of connections than the 5000 default in IIS7.

References:

[1] Performing Asynchronous Work, or Tasks, in ASP.NET Applications.

[2] ASP.NET Thread Usage on IIS 7.5, IIS 7.0, and IIS 6.0



A review of asynchronous programming patterns in .net


In Visual Studio 11, C# and VB.NET will gain new keywords like async and await for asynchronous programming. Before we dive into it, I will first give a brief preview on what we have so far.

IAsyncResult Pattern

IAsyncResult pattern has existed since .net 1.x. The class that implements pattern would implement Beginxxx and Endxxx methods.For example, the WebRequest class has BeginGetResponse and EndGetResponse in additional to synchronous GetResponse method.  Here is the signature of the BeginGetResponse method:

public virtual IAsyncResult BeginGetResponse( AsyncCallback callback, Object state )

The caller of the method needs to supply a callback function which will be call when the asynchronous operation is over. The callee will usually create another thread to do the actual operation and immediate an IAsyncResult to the caller. Here are the members of IAsyncResult:

Member Description
AsyncState An optional application-specific object that contains information about the asynchronous operation.
AsyncWaitHandle A WaitHandle that can be used to block application execution until the asynchronous operation completes.
CompletedSynchronously A value that indicates whether the asynchronous operation completed on the thread used to call BeginOperationName instead of completing on a separate ThreadPool thread.
IsCompleted A value that indicates whether the asynchronous operation has completed.

The caller of Beginxxx method can do one of the following:

  1. Wait on the AsyncWaitHandle if the caller needs to do processing after the async operation.
  2. Poll the IsCompleted and AsyncState for completion and possibly the progress.
  3. Do nothing. Wait for the callback to be called.
  4. Call the Endxxx method. If it is called before the completion of the async operation, the calling thread will block until the asynchronous operation is complete.

Event-based Asynchronous Pattern

Since .net 2.0, we gain another asynchronous pattern ? the Event-based Asynchronous Pattern (EAP). EAP was created to allow a richer event model. The class that implement EAP can raised multiple events during a single asynchronous operation so that the callee does not have to poll the class.

The class that implements EAP uses xxxAsync naming conversion for its asynchronous methods. The class can optionally implements xxxCancelAsync methods or simply a CancelAsync method to allow caller to cancel the asynchronous operation. When a caller calls a xxxAsync method, the method will immediately return. The caller needs to subscribe one of the events exposed by the class for notifications of completion and progress. WebClient and BackgroundWorker are two typical components that use this pattern. For library designers, MSDN has a nice article descripting when to use which pattern.

Task-based Asynchronous Pattern

.Net framework 4.0 introduced yet another way to run asynchronous operation ? the Task class in the Task Parallel Library.  Although the task parallel library is about parallel execution and is much more than asynchronous programming, the .net framework 4.5 uses it as the base for yet another asynchronous pattern ? the Task-based Asynchronous Patterns (TAP). The class that implements TAP would expose xxxAsync methods, just like EAP. However, the xxxAsync methods return Task. The callee can then use the members of Task to check completion or progress, wait or continue with another operation. This pattern is the basis for the async and await keywords in Visual Studio 11; the methods that support TAP can be marked using the async keywoard and then consumed asynchronously with the await keyword. That is why only methods return Task, Task or void (that is, no results) can be marked with async.



A jQuery Plugin for Google Map Thumb(Magnifier)


        Introduction:


                    Recently in one of my project I came across with a requirement to show a thumbnail(or magnifier) in Google map because there was a lot of custom objects(line, polygon, etc) on my Google map due to which the map become obscure. I was able to successfully implement this option. But I have also created a jQuery plugin, so that if anyone else came across the same issue, can reuse the functionality. In this article, I will show you how to use this plugin. Here is a quick demo.


        Description:


                    I am not going to bore you further, just download the jquery.gmapthumb sample from github or install it via nuget. Also, a sample has been attached with this blog. You just need to include the jquery.gmapthumb.js(or jquery.gmapthumb.min.js) file in your page and add this script. $('#map').gmapthumb([map]). Note that the map object is inside square bracket(array) because you can bind multiple maps with just one line(see example in above link for further reference). Finally, you need to place the img folder inside your page directory.


        Summary:


                    In this article, I showed you how you can show a thumbnail(magnifier) in your Google map very quickly. I have also attached a sample with this blog. Hopefully you will enjoy this article too.





Hiding buttons on the SharePoint ECB with JavaScript


Some of my best discoveries come from forum questions. Not that I'm the first one to discover it, mind you -- I'm well aware that my wheel has probably been invented countless times -- but my mind grows best when I have to research a solution for someone else's problem (maybe that's why I like consulting).

Today's question was a simple one: how do I remove the Edit Item and Workflows buttons from the ECB (Edit Control Block) in a particular list view? If you're not familiar with the ECB for a list item, go to a list and select any list item; the List Item ECB will appear in the ribbon with commands like New Item, New Folder, etc. 

Since a list view is just an aspx file, we can add some client-side code -- either directly in the page, or by way of the Content Editor Web Part. Our code depends on jQuery, and looks like this:

$("td").hover(function() {
	hideEditAndWorkflows();
});
$("input").hover(function() {
	hideEditAndWorkflows();
});
function hideEditAndWorkflows() {
	$("#Ribbon\\.ListItem\\.Workflow").css("display", "none");
	$("#Ribbon\\.ListItem\\.Manage\\.EditProperties-Large").remove();
	}

If you're a jQuery novice, you'll want to visit jQuery.com and get the latest version -- simply upload the necessary JS file to a library and add a script link to it in the page (there's a ton of reference material out there, including the excellent documentation at the jQuery site).

You may wonder at the backslashes we're using in the hideEditAndWorkflows function.  Since these element IDs contain special characters (normally the dot denotes a class in CSS selectors), we have to escape them so that we can pass them properly through the system.

Once you have this code in place, you'll see the Edit and Workflows buttons for a moment after clicking the first list item on the page; after that, they should disappear and be completely unavailable to your average user.

Of course, client-side techniques like this will only go so far; if someone is technically adept and has the ability to perform these operations, he or she can open up the developer console and find the missing pieces.  Be aware of this whenever you manipulate the SharePoint UI with JavaScript; while it's fun and easy, this technique should never be a substitute for proper governance.

Enjoy!