Posts

Briefly Stateless and Stateful Design in Programming

Stateless programming is related to the mathematical notion of a function, which when called with the same arguments, always return the same result. This is a key concept of the functional programming paradigm.

In other words;
Stateless means there is no memory of the past. Every transaction is performed as if it was being done for the very first time.

Stateful means there is memory of the past. Previous transactions are remembered and may affect the current transaction.

RESTful we services are by design stateless, so is ASP.NET MVC.

Stateless: //The state is derived by what is passed into the function function int addOne(int number) { return number + 1; } Stateful: //The state is maintained by the function private int _number = 0; //initially zero function int addOne() { _number++; return _number; }

Fix for Umbraco Backoffice Login Problem - umbraco/backoffice/UmbracoApi/Authentication/PostLogin - 400 Bad Request

Image
If you ever see that you can not login to Umbraco backoffice anymore even though you haven't changed anything, this could be because of 301 Url Tracker umbraco package.

For my case; this package was messing up paths for Umbraco Backoffice API mehtods and deleting all records in icUrlTracker table has fixed my problem.

There are other suggestions like updating the web.config useLegacyEncoding setting but this hasn't worked for me.

Hope it helps.



Fix for "Umbraco PostSave 400 Bad Request"

Custom error config changes might cause some Umbraco 400 response issues. As a results while saving and publishing umbraco content, you might see "PostSave 400 Bad Request" messages. In my case I also couldn't see some umbraco mandatory field validation messages.

In order to fix it you can add the following line to your web.config and it should start working.
  <location path="umbraco">
    <system.webServer>
      <httpErrors existingResponse="PassThrough" />
    </system.webServer>
  </location>
Request URL: https://DOMAINNAME/umbraco/backoffice/UmbracoApi/Content/PostSave Request Method: POST Status Code: 400 Bad Request

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\"