Wednesday, 23 March 2016

How to identify the application pool for a worker process (Windows Server 2012 and 2012 R2 using IIS 8)

Use the following command to determine which application pool maps to your w3wp.exe worker instance. This is particularly handy with SharePoint as it has 3 w3wp.exe processes running at any one time by default.
cd %windir%\system32\inetsrv
appcmd list wp

This will give you an output similar to the following:

C:\Windows\System32\inetsrv>appcmd list wp
WP "21192"  (applicationPool:SharePoint - 80)
WP "12256" (applicationPool:SecurityTokenServiceApplicationPool)
WP "19972" (applicationPool:5f2e9be121504641ae144bcae3b8cf6e)
DDK

Tuesday, 22 September 2015

Impersonation of Web Users in ASP.NET/SharePoint 2013 without a password

There seemed to be a lack of samples available to demonstrate how Windows impersonation can be done within the context of a web application (such as SharePoint 2013 or ASP.NET). Most of the examples use the "LogonUser" Windows API call to get a user token. e.g. https://msdn.microsoft.com/en-us/library/chf6fbt4.aspx. However - that call requires a password to work. You don't really want all your user passwords to have to sit in a secure store to enable impersonation!

In my scenario, I had to write to a file through an existing COM Component via a .NET COM Interop library. It depended on the write operation being done from the context of a valid user - otherwise the file wouldn't be stamped correctly with author metadata.

To do this, I had to use an overload of the WindowsIdentity constructor which accepts a UPN (User Principal Name). From there, you can impersonate users within your code at will.

NOTE: the account that is doing the impersonation (e.g. svcSP) will need to have the "Act as Part of the Operating System" right as defined in your Local User Policy for this to work.

Code Sample:


void Main()
{
 var userName = "LOCALDEV\\david.klein";
 PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

 var user = UserPrincipal.FindByIdentity(ctx, userName);

 if (user != null)
 {
 var upn = user.UserPrincipalName;
 Debug.Print(upn); 
 WindowsIdentity id = new WindowsIdentity(upn);
 WindowsImpersonationContext wic = id.Impersonate();    
 try
  {
   // Do what you need here under the impersonation context.
   var currentId = WindowsIdentity.GetCurrent().Name; 
   Debug.Print(currentId);
  }
  finally
  {
   wic.Undo();
  }
 }
}

Monday, 20 April 2015

Microsoft Team Foundation Server 2013 Update - Error When Installing - "SQL Server Reporting Services is configured to require a secure connection."

You may get the following exception when upgrading to Team Foundation Server 2013 (TFS 2013) or update packages - when you are using self-signed certificates or your SQL Report server runs unsecured (not using SSL):

TF255455: SQL Server Reporting Services is configured to require a secure connection. However, no HTTPS URL is configured with a valid certificate. Use the Reporting Services Configuration Manager to configure or remove HTTPS support. For more information see http://go.microsoft.com/fwlink/?LinkId=179982


To resolve this issue (without getting valid certificates or securing your site), you can go to your Microsoft SQL Server Reporting Services (SSRS) folder and find the rsreportserver.config  file. This is typically in:

C:\Program Files\Microsoft SQL Server\MSRSXX.<ServerInstance>\Reporting Services\ReportServer\rsreportserver.config             

Update the "SecureConnectionLevel" from 2 to 0 - and you will be able to run the update. Change it back after the update has completed.



DDK

Friday, 23 January 2015

How can I easily have different app.config files for different build configurations in MSBUILD?

There are a few different proposed solutions I have seen suggested, some including recommendations involving 3rd party tools and Visual Studio Transformation Extensions. The following is the simplest method I have found. It involves a violation of the DRY principle (Don't Repeat Yourself) as the app.config files are duplicated (due to the lack of transforms) - but I considered this to be a small sacrifice based on the simplicity of the solution.

Steps:
1) Unload your Project file (csproj) file in Visual Studio and Right click and select "Edit {My Project Name}.csproj" on that same file to edit it.
2) Add a folder for each MSBUILD configuration that you want and put your different App.Config files in those subfolders e.g. \Release\App.config and \Debug\App.Config
2) Find the section in your csproj project file <None Include="App.config" /> and replace it with the following conditional Include statements for each of your MSBUILD configurations:
<None Condition=" '$(Configuration)' == 'Debug' " Include="Debug\App.config" />
<None Condition=" '$(Configuration)' == 'Release' " Include="Release\App.config" />

When you build, it will use either of the application configuration files that you have created and put them in the relevant build configuration output directory.

DDK

Monday, 17 November 2014

SQL Server Database Projects and Visual Studio 2012, 2013 - Why Doesn't My DACPAC Post-Deployment Script Run?

SQL Server Database Projects are a new feature from Visual Studio 2012 onwards.
The SQL DACPAC format is generated by SQL Database Projects and is a Microsoft-endorsed way for deploying SQL schema changes as part of a deployment package (also known as a Data Tier Application). These can be deployed by a setup package or even a SQL Database Administrator through SQL Server Management Studio.

I noticed today that every time I built my project, it would include the wrong post-deployment SQL script file inside my DACPAC - so my reference tables were not populated with data correctly.

Turns out that there can only ever be one designated Post-Deployment Script in a SQL Server Database Project. I originally thought it was just a naming convention that was used to find the designated post-build file (i.e. anything named "Script.PostDeployment*.*".

This was not correct - you just have to make sure it is labelled as the Post-Deployment script for that project as per the file properties below.



As a side note, I generated the SQL MERGE statements for reference/lookup data using the dbo.sp_generate_merge tool on github:
https://github.com/readyroll/generate-sql-merge

DDK

Wednesday, 14 May 2014

China, Hong Kong and Macau Trip 2014

Arrived home this week after a lengthy trip around Hong Kong, Macau and China. Went with the family including dad this time. We saw some truly jaw-dropping scenery this time round. See below.

The highlights:

1) China - The clouds curling around Huangshan (Yellow) Mountain and the Extremely Steep Steps.

Known as "Yellow Mountain" to the average guilau. It was exactly like the old Chinese watercolour paintings you see everywhere (and they obviously inspired the scenery from the movie Avatar.). The 1000s of stairs were quite punishing - and the lack of hand rails, gale-force winds and sheer drops off granite cliffs was too hair raising for my Dad (plus he had a cold) - who pulled out.













Fairy Bridge (ahem. I'm not the fairy...)




 
 
These Guys get 100 Yuan Per Container they get to the Top (10km of stairs!):
 

 


2) China - Cycling Around Hangzhou (aka the "Most Beautiful City in China") and the West Lake
The whole city of Hangzhou is like a big jungle with beautiful Willows, pagodas and bridges everywhere. Probably the most livable city in China from my perspective as they take pride in how their city looks. Last time I went there, I got food poisioning so this experience was marginally better.

The 7km Tea Plantation Walk Near Hangzhou










3) China - Great Wall of China at Mutianyu and the Mega-Taboggan on the way back down Lisa and I had been to the Badaling section of the Great Wall in 2007 - but never to the less touristy section at Mutianyu. There you can actually move without a loud Chinese Tourist Operator deafening you with a megaphone in your ear and a dictatorial snarl to their voice.

Zach and Chinese 70's moustache guy

Some videos of the kids mucking around on the Great Wall:

a) Great wall of China Song inspired by the Wolf of Wall Street - http://youtu.be/xskGz1nrz8Q
b) Zach and Heidi - General Horseplay - Running Up and Down the Wall - http://youtu.be/Kp7PTl0cq-M


4) China - Eating the Poisonous Fugu Puffer Fish and Stinky Tofu in Shanghai

I've eaten a lot of weird and wonderful animals in China - but never had the poisonous (and potentitally deadly) Puffer fish Fugu. Had it on the river side of Shanghai a few blocks from the Shanghai Pearl Tower. Apparently your tongue is meant to tingle from the neurotoxins - but I found it had limited effect. Well at least I didn't suffer from paralysis and rapid death like hundreds of people in Japan in the 1950s! That's why serving of it is now strictly controlled and licensed.

 

 
I'd also never been brave enough to eat Cho Dofu (or Stinky Tofu). I will not be doing it again - as it smells and tastes like a perverse combination if Urine and Faeces. Yummo!


5) Macau - Touring St Pauls, and The Venetian and Galaxy Casinos.

The massive scale of the Venetian Casino and it's lifelike sky meant that:
a) We regularly got lost (that's probably by design as they never want you to escape before you gamble your money away.
b) We regularly experienced "The Truman Show" moments as the sky high above our heads seemed to move before your eyes if you look at it long enough - but it was just a well painted and lit ceiling.




There is a few hundred metres of canals within the Casino.
 
 
The lack of signs meant that we got lost a couple of times. This is Heidi having enough of walking around in circles:


The Portuguese Architecture on the way to St Pauls


6) China - Shanghai - Bar Rouge @ Bund 18 - Unfortunately missed out on the pole dancing and the "Bar on Fire" (a definite OH&S Issue and wouldn't be allowed in Australia) - on account of the weather but the view was spectacular and the Tiramisu cocktail was a winner. Most of the people in the bar had a distinctly British accent.


7) Chinglish Signs 

Some of the Awesome examples of the obligatory "Chinglish" signs I came accross this time. These included:

a) The "Chubby Lady" Fashion Store. It was not for Plus size women. "Mudd" fashion was also an inappropriate mechanism for generating interest in their clothing lines.


b) Instructions in the urinal to stand closer to avoid spillage - "One small step for forward, a big step for civilization". An interesting attempt at Chinese self-effacement - and recognition of the apalling state of urinals in China generally.
c) Engraved on a steel sign, instructions that "no verminous of filthy people are allowed in the park"... and that they must not "expose or exhibit sores when begging". Even beggars need to have standards.

8) China - Single-wheeled Segways and Mini-Segways

I saw about 20 of these on streets in China that people ride to work - I've never seen anything like it. Must have a very powerful gyro. Most of the motorbikes are all now electric (a big difference from my last visit 3 years before).

9) China - Yuanmingyuan  Ruins and Terracotta Warriors in Xian
Yuanmingruan are the ruins left of the old Summer Palace during the Opium Wars - the British and French Destroyed the massive fountains and palace complex that they helped to create. Dad (as a history teacher) - finally got to see the Terracotta warriors - and was very impressed.

The Terracotta Warriors - every one of them different. All holding weapons with a chromium covering (allegedly 2200 years before the Germans discovered the technique) - so they were still shiny when excavated. The warriors were all coloured like the Chinese Temples - with blue faces.

Yuanmingyuan Ruins Destroyed in the Opium Wars

Yuanmingyuan Maze

10) China - Cooking my own food at a street vendor in Shanghai

Like cooking your own steak in the poor man's Oaks!


11) The large number of times random people asked the kids and I to have photos with them

I had 4 groups ask me to hug them for photos just in Tiananmen Square! Zach then complained that everyone wanted photos with Heidi and I - "Who's taking a photo with me???". Sure enough he was asked about 10 minutes later!

12) On our Cathay Flight Home, they played the Chinese Language of "Prepare for Landing" while we were in the middle of the Ocean!The captain apologized shortly after this boo-boo - as they had no native Mandarin speakers on the plane and got the messages mixed up. Shortly after, they asked if a doctor on the plane for an emergency. I would have had a heart attack too if I believed the message... when we landed, several people clapped and cheered. Apparently some countries have that as a tradition - but I think people were relieved that they were still alive...

There are about a million other things I could say about the trip - but that will have to do!

Till Next Time,









DDK