Showing posts from 2017

Fix for "Websites cannot be started unless both the Windows Activation Service (WAS) and the World Wide Web Publishing Service (W3SVC) are running, Both services are currently stopped"

Sometimes after iisreset, it is possible to see the following exception.

In order to fix it; just run the Command Prompt as Administrator and type the following script to fix it;

C:\WINDOWS\system32>net start w3svc

This should fix your problem.

IIS Exception:

"Websites cannot be started unless both the Windows Activation Service (WAS) and the World Wide Web Publishing Service (W3SVC) are running, Both services are currently stopped"

Umbraco Role Based Protection - Getting A Content Page's Membership Roles & Getting Membership Roles of a User

If you have set up Public Access roles for a content page using the Umbraco CMS and you need to reach the roles of this content page in the code behind, then this is how you can do it;
var roles = umbraco.cms.businesslogic.web.Access.GetAccessingMembershipRoles(content.Id,content.Path); If you need to get all roles, then this is how you can get it;
var allRoles = ApplicationContext.Current.Services.MemberService.GetAllRoles(); In addition to this, we can get the member roles as shown below;
var memberRoles = System.Web.Security.Roles.GetRolesForUser(member.Username).ToList();
Happy coding.

C# Interpolated Strings

String interpolation. This feature inserts values into a string with simple syntax and it is very useful. It is very much like string.Format, but variables may be accessed directly. Its performance is also similar to string.Format calls.

Below is an example of the string interpolation syntax. See that it always starts with a "$" sign.

int string1 = 100; int string2 = 2; string animals = $"First string = {string1} and Second string = {string2}";

How to tell Visual Studio to copy the complete folder and sub folder/files to the output directory?

First add your folder(This is my folder: XULRunner21_0) to your project with all the items added to your project, and then go to your project's Properties>Build Events and write the following command line into Post-build event command line area. 
After building the solution, you should see under bin folder of your project, XULRunner21_0 folder will be created with all the items in it. That is all, hope it help.

PS: While publishing, if we need to copy some folders into the bin folder, we need to follow this documentation and use target events for publishing.

xcopy /E /Y "$(ProjectDir)XULRunner21_0\*""$(ProjectDir)$(OutDir)XULRunner21_0\"

SQL to Find Umbraco Nodes using a Certain Umbraco Document Type

In order to get the Umbraco nodes which use a certain umbraco Document Type, you can use the following SQL script. You can then simply login to umbraco backoffice and search for the nodeId value in there and find the node that you want.

SELECT*FROM cmsContent C INNERJOIN cmsContentType CT ON C.contentType = CT.nodeId INNERJOIN umbracoNode N ON C.nodeId = WHERE CT.alias ='YourDocumentTypeAlias'

Upgrading from Umbraco Contour to Umbraco Forms: Fix for Could not load type 'Umbraco.Forms.Core.Services.RecordService' from assembly 'Umbraco.Forms.Core, Version=, Culture=neutral, PublicKeyToken=null'.

If your Umbraco website is already using Umbraco Contour and if you want to upgrade to Umbraco Forms then you might experience "Could not load type 'Umbraco.Forms.Core.Services.RecordService' from assembly 'Umbraco.Forms.Core, Version=, Culture=neutral, PublicKeyToken=null'." while installing Umbraco Forms.

Please go to this Umbraco Forums url to see how I fixed my problem.

After installing the Umbraco Forms successfully, then you might want to remove Contour items from the Macro Dropdown List. To do that simply go to /Developer/Macros section and delete the Contour items.

That is all, hope this post helps.

Tracking MS SQL CPU Usage

--T-SQL to identify the Top 20 most costly queries in terms of Total CPU:
SELECTTOP 20     st.dbid, DB_NAME(st.dbid)AS Database_Name,     qs.sql_handle,     qs.execution_count,     qs.total_worker_time AS Total_CPU,     total_CPU_inSeconds =--Converted from microseconds     qs.total_worker_time/1000000,     average_CPU_inSeconds =--Converted from microseconds (qs.total_worker_time/1000000)/ qs.execution_count,     qs.total_elapsed_time,     total_elapsed_time_inSeconds =--Converted from microseconds     qs.total_elapsed_time/1000000,     st.text,     qp.query_plan FROM sys.dm_exec_query_statsAS qs CROSSAPPLYsys.dm_exec_sql_text(qs.sql_handle)AS st CROSSapplysys.dm_exec_query_plan(qs.plan_handle)AS qp ORDERBY qs.total_worker_time DESC
--This shows the number of connections per each DB: SELECT DB_NAME(dbid)as DBName,