<description /><item><guid isPermaLink="false">24678</guid><link>https://dejanstojanovic.net/aspnet/2022/june/using-dotnet-nuget-package-vulnerability-scan-in-azure-devops-build/</link><category>.NET</category><title>Using dotnet nuget package vulnerability scan in Azure DevOps buildSince December 2021 when Log4Shell vulnerabilty caused by popular package for logging in Log4j for Java was discovered here is raised certain level of awareness of using OpenSource packages in application. Because of these cases it is critical that you have indicator whether you are using a dependency with reported vulnerability before you make your application available for wide audience, practically before you do the production releaseSun, 05 Jun 2022 12:17:55 -04002022-06-05T12:17:55-04:0024676https://dejanstojanovic.net/aspnet/2022/may/protecting-static-files-in-aspnet-core-using-custom-middleware/.NETProtecting static files in ASP.NET Core using custom middlewareThe most common scenario for static files is just to serve them as they are without any additional hassle or access rules.To serve static content which are often just images, css, javascript or other common static web content, you just need to involve static content middleware in your ASP.NET core application pipeline. Adding static content in ASP.NET Core applications is as simple as adding wwwroot folder to root of your web application and adding StaticFiles middleware to your pipeline. By default these files will become publicly available, but in the further text we'll deal with how restrict access to these static files you have in your application. Thu, 05 May 2022 14:20:25 -04002022-05-05T14:20:25-04:0024667https://dejanstojanovic.net/sql/2022/february/select-column-names-with-values-from-sql-server-database/SQL/T-SQLSelect column names with values from SQL Server databaseFetching the data in it's original form from SQL relational database is the most common way of getting the data stored. For example, to get all column from Products table in Northwind database is pretty straight forward. Tue, 22 Feb 2022 05:33:45 -05002022-02-22T05:33:45-05:0024652https://dejanstojanovic.net/aspnet/2021/december/supporting-multiple-authentication-schemes-in-aspnet-core-webapi/.NETSupporting multiple authentication schemes in asp.net core webapiIs is not so often than you have to use more than one authentication schemes in your project, but there are some corner cases when you have to do so. One of it is a scenario where you are supporting some weaker authentication schema like basic http authentication where credentials are supplied pretty much on every request. This kind of loosen security schema is to some limited extend suitable for internal APIs meaning that no other than users or most likely application within your organization network will accessMon, 20 Dec 2021 14:10:00 -05002021-12-20T14:10:00-05:0024649https://dejanstojanovic.net/aspnet/2021/december/controlling-the-flow-of-migrations-in-ef-core/.NETControlling the flow of migrations in EF CoreEF Core has migrations as a way of restoring the database structure inherited from Entity Framework and for the most of the cases all you have to do to setup your database structure changes when deploying your new application version is to call the Migrate method from your DbContext.Database property. It is not a perfect solution but as I mention, it works great for majority of the cases and takes of the complexity of sorting out order for execution of pending changes so you can focus on business logic of your application. Sun, 12 Dec 2021 00:01:57 -05002021-12-12T00:01:57-05:0024643https://dejanstojanovic.net/aspnet/2021/november/unit-of-work-pattern-with-dapper/.NETUnit of work pattern with DapperPeople often try to compare Dapper and Entity Framework. Although they both have same goal and that is reading and modifying the data against the database, they take completely different approach in doing so and therefore this comparison is not really valid. Entity framework is more robust as the name says framework, while Dapper is simple object mapper which is down the line set of extension methods on top of the ADO classes which allow easier manipulation with data in the databaseSun, 28 Nov 2021 06:11:59 -05002021-11-28T06:11:59-05:0024635https://dejanstojanovic.net/powershell/2021/november/adding-centralized-secrets-service-to-azure-service-fabric-cluster/PowerShellAdding centralized secrets service to Azure Service Fabric clusterAzure Service Fabric is a great platform to host services for your distributed solution. It allows you to easily deploy and scale your applications and services. Apart from these out of the box functionalities which it is essentially build for, it also comes with secrets service which allows you to store and retrieve secret values for your applicationMon, 01 Nov 2021 12:15:05 -04002021-11-01T12:15:05-04:0024631https://dejanstojanovic.net/aspnet/2021/september/adding-display-name-to-enum-values/.NETAdding display name to Enum valuesEnums are great way do list available options for certain variable values in your code. However, they do not come without limitations and they are not suitable for all scenarios. One of those limitations are Enum value names which have restrictions similar to variable name restrictions in C#Tue, 21 Sep 2021 01:24:53 -04002021-09-21T01:24:53-04:0024620https://dejanstojanovic.net/aspnet/2021/june/c-scripting-with-net-core-global-tool/.NETC# scripting with .NET Core global toolI assume since you are reading this article you are involved in development of applications using C# and .NET platform. Microsoft .NET and C# have been around for quite a while but there is not much talk on haw you can use C# for writing code apart from creating your projects in your IDE of choice and compiling them to executables. This is typical approach for writing robust applications and that is fine, but from time to time, this whole ceremony of creating a project, adding packages and libraries just to run for example a simple scheduled task that cleans up old logs from IIS seems like and overkillWed, 16 Jun 2021 06:29:15 -04002021-06-16T06:29:15-04:0024607https://dejanstojanovic.net/powershell/2021/june/customizing-powershell-with-oh-my-posh-v3/PowerShellCustomizing PowerShell terminal with oh-my-posh v3Last year I wrote an article on how to Customizing WSL2 on Windows with screenfetch and oh-my-zsh as I was spending a lot of time in WSL2 doing some heavy development for Linux platform using .NET Core. However recently I found myself working a lot in PowerShell prompt mainly with Git and really missed the customization I did for WSL, so I decided to customize my PowerShell console as wellSun, 06 Jun 2021 04:19:50 -04002021-06-06T04:19:50-04:0024604https://dejanstojanovic.net/aspnet/2021/may/using-interceptors-with-dependency-injection-in-entity-framework-core/.NETUsing interceptors with dependency injection in Entity Framework CoreI while ago I wrote an article on how to Access multiple databases from the same DbContext in EF Core which relies on interceptors to mutate the SQL query diring execution. This code works just fine and it updates the command prior to it's execution, but it lacks in option to inject registered services to it's constructor as i used new keyword to initialize class instances. Adding interceptor without dependency injection Tue, 25 May 2021 12:11:02 -04002021-05-25T12:11:02-04:0024601https://dejanstojanovic.net/aspnet/2021/may/implementing-soft-delete-in-ef-core-using-triggers/.NETImplementing soft delete in EF Core using triggersImplementation approach for soft delete is more-less straight forward thing. Instead of deleting data record, you introduce a flag which will mark the record as deleted and you can simply filter out on it and not show the data with the flag set. This way you do not loose data, but you restrict the end user to see it. This way of "deleting" data records, or better said marking them as deleted applies for certain types of applications, but sometime this requirement may come later as a new feature while the actual delete is in placeSat, 08 May 2021 06:35:02 -04002021-05-08T06:35:02-04:0024591https://dejanstojanovic.net/aspnet/2021/april/handling-file-upload-in-aspnet-core-5-with-swagger-ui/.NETHandling file upload in ASP.NET Core 5 with Swagger UIIn 2019 I worked on a REST API service which accepts files and stores them. Back then in .NET Core 2.2 I wrote custom Swagger operation filter which I described in article Handling file uploads in Swagger UI with ASP.NET CoreSat, 24 Apr 2021 22:28:32 -04002021-04-24T22:28:32-04:0024580https://dejanstojanovic.net/aspnet/2021/march/generic-type-controller-methods-in-aspnet-core/.NETGeneric type controller methods in ASP.NET CoreGeneric types are great way to re-use methods and apply the same logic to different types. However, they come with some limitations, especially in ASP.NET realmFri, 26 Mar 2021 03:09:45 -04002021-03-26T03:09:45-04:0024574https://dejanstojanovic.net/powershell/2021/february/setting-azure-devops-pipeline-variable-from-powershell-script/PowerShellSetting Azure DevOps pipeline variable from PowerShell scriptWhen using Azure DevOps Pipelines or Releases, it is pretty easy to move informations from the pipeline/release into the target artifact package or folder on the target environment. What can be tricky if you need to dictate your pipeline/release based on the value from your code base or maybe the environment to which you are deploying to. As a simple example I set the version attribute in in my .csproj file which I will use to tell UseDotNet task in my build pipeline which SDK to use to perform .NET Core project build. Mon, 01 Feb 2021 18:13:53 -05002021-02-01T18:13:53-05:0024570https://dejanstojanovic.net/aspnet/2021/january/mocking-view-mapped-dbsets-with-xunit-in-ef-core/.NETMocking view mapped DbSets with XUnit in EF CoreUsing in-memory DbContext is a great way to mock your actual DbContext in unit tests. You basically initialize the instance of your DbContext and seed some random data before you assert the result of your repository methodSun, 17 Jan 2021 00:18:54 -05002021-01-17T00:18:54-05:0024562https://dejanstojanovic.net/aspnet/2020/december/setting-up-sql-server-idistributedcache-with-migration-in-aspnet-core/.NETSetting up SQL Server IDistributedCache with migration in ASP.NET CoreCaching data using Microsoft SQL Server may not be the most popular way of caching data because of the performance comparing to caching data to Redis, but it is maybe the most convenient way to keep your state of the application outside the process itself. Beside, if you are already using SQL Server database, you can just move the caching infrastructure to a separate schema inside the same database and keep using it until requirements are met for cache storage of better performance (like Redis for example). This makes infrastructure not so complex and less dependent, again until the requirements for something faster are met. Sat, 19 Dec 2020 20:25:38 -05002020-12-19T20:25:38-05:0024552https://dejanstojanovic.net/aspnet/2020/december/representing-available-string-values-for-parameters-as-list-in-swagger-aspnet-core/.NETRepresenting available string values for parameters as list in Swagger ASP.NET CoreSwagger is a great way do describe your RESTful API. In ASP.NET it is pretty easy to wire up your OpenAPI documentation with your service facade with Swashbuckle NuGet packageFri, 11 Dec 2020 04:44:59 -05002020-12-11T04:44:59-05:0024543https://dejanstojanovic.net/aspnet/2020/november/running-multiple-queries-at-the-same-time-in-ef-core/.NETRunning multiple queries at the same time in EF Core Since the time of ADO in .NET one of the limitations was that one connection can execute single command at the time. Same limitation Entity Framework inherited and you can execute single command at the time per instance of your DbContextTue, 24 Nov 2020 04:28:30 -05002020-11-24T04:28:30-05:0024534https://dejanstojanovic.net/aspnet/2020/november/accessing-multiple-databases-from-the-same-dbcontext-in-ef-core/.NETAccessing multiple databases from the same DbContext in EF CoreIt is not uncommon to have a requirement to access tables or views in different databases in the same query. In order to be able to do your joins on tables or views in different databases you need to do it in the same connection instance which is bound to DbContext, therefore this access as to be accomplished from the same DbContext instanceTue, 17 Nov 2020 05:19:55 -05002020-11-17T05:19:55-05:0024517https://dejanstojanovic.net/powershell/2020/september/customizing-wsl2-on-windows-with-screenfetch-and-oh-my-zsh/PowerShellCustomizing WSL2 on Windows with screenfetch and oh-my-zshWindows Subsystem for Linux or WSL i a great way to have a Linux environment easily accessible from your development environment on Windows. With latest Windows10 May 2020 update 2020H1 WSL got a major update WSL2 which enables even more fluent integration of Linux kernel into Windows10. I will assume that you are already using WSL2 and you are familiar with initial setup of it on Window10Sun, 27 Sep 2020 17:12:13 -04002020-09-27T17:12:13-04:0024508https://dejanstojanovic.net/aspnet/2020/september/building-and-using-advanced-net-core-cli-global-tools/.NETBuilding and using advanced .NET Core CLI global toolsOnce .NET Core 2.1 SDK introduced support for global tools I wrote a brief article on how to create a simple global CLI tool in .NET Core Building advanced .NET Core Global Tool using CommandLineUtils package. While this is fair enough informations to kick-start you project and create a simple global tool to use from the command line, I found out there is more to it in order to have the tool built, published, distributed and used especially when you are dealing with real-life applications that need to have a CLI as a part of the solution. Fri, 11 Sep 2020 19:07:55 -04002020-09-11T19:07:55-04:0024501https://dejanstojanovic.net/aspnet/2020/september/seeding-data-in-ef-core-using-sql-scripts/.NETSeeding data in EF Core using SQL scriptsNot so while ago I wrote an article on Seeding data with Entity Framework Core using migrations. This approach relies on EF Core migrations to ensure seeding of specific data is done only once using __EFMigrationsHistory table to track structural migrations as well as data seeding migrations. In large number of cases this approach works just fine and you do not need to do any adjustments or add any additional tables, just use migrations mechanism out of the boxSun, 06 Sep 2020 06:29:39 -04002020-09-06T06:29:39-04:0024490https://dejanstojanovic.net/aspnet/2020/july/basic-authentication-with-swagger-and-aspnet-core/.NETBasic authentication with Swagger and ASP.NET CoreBasic authentication is not so popular authentication method nowadays. There is a valid reason for that and that is mainly the way credentials are used to authenticate to access the resourcesThu, 30 Jul 2020 04:42:48 -04002020-07-30T04:42:48-04:0024484https://dejanstojanovic.net/aspnet/2020/july/seeding-data-with-entity-framework-core-using-migrations/.NETSeeding data with Entity Framework Core using migrationsAs much as it is important for testing the functionality of the application, data seeding can also be used to pre-load some values like lookups not only to development and test environment but also to populate these values in production as well. Seeding of data can be done in several ways and in this article I will go through two ways of seeding data. Both of them have their pros and cons and it is up to you to pick the way you want to have your data pre-seeded in your application database. Tue, 21 Jul 2020 06:44:26 -04002020-07-21T06:44:26-04:0024475https://dejanstojanovic.net/aspnet/2020/june/dealing-with-default-api-versions-in-swagger-ui/.NETDealing with default API versions in Swagger UIHaving your REST API versioned is important for evolving of the service over time. Especially if your service is exposed t multiple 3rd party clientsSun, 21 Jun 2020 02:01:50 -04002020-06-21T02:01:50-04:0024473https://dejanstojanovic.net/sql/2020/may/identifying-opened-connections-for-the-specific-application-in-sql-server/SQL/T-SQLIdentifying opened connections for the specific application in SQL ServerObject relational mappers or ORMs are a great tool which can significantly reduce application development time, but if they are not use wisely they can cause bottlenecks and performance issues. Same goes for dependency injection containers. The lifetime of the components, especially the ones that can cause recurse locks like SQL Server connections must be as short as possible and they should be released as soon as work is done. Sat, 23 May 2020 22:59:11 -04002020-05-23T22:59:11-04:0024462https://dejanstojanovic.net/aspnet/2020/may/setting-up-code-coverage-reports-in-azure-devops-pipeline/.NETSetting up code coverage reports in Azure DevOps pipelineI while ago I wrote and article about Publishing .NET Core code analysis to SonarCloud from Azure build pipeline. Although SonarCloud is a great platform for analyzing your code coverage and dry code analysis, it can add additional cost to your projectMon, 11 May 2020 17:21:10 -04002020-05-11T17:21:10-04:0024460https://dejanstojanovic.net/aspnet/2020/may/using-polly-for-retrial-policies-with-autofac/.NETUsing Polly for retrial policies with AutofacSome time ago I wrote an article which explains how to Increase service resilience using Polly and retry pattern in ASP.NET Core. This is a great way how to easily implement retrials when using .NET Core dependency injection, but in case of using Autofac with .NET Framework 4.x you do not have many out of the box solutions.  However, Polly as a library is not specifically built for .NET Core and using it with other dependecy injection packages such as Autofac is fairly easyTue, 05 May 2020 03:42:38 -04002020-05-05T03:42:38-04:0024457https://dejanstojanovic.net/aspnet/2020/april/validate-configurations-with-fluentvalidation-in-aspnet-core/.NETValidate configurations with FluentValidation in ASP.NET CoreConfiguration is an important part of the application. In many cases it determines how the application will behave, for example when you have different configurations per environmentWed, 29 Apr 2020 04:35:35 -04002020-04-29T04:35:35-04:0024445https://dejanstojanovic.net/aspnet/2020/april/combining-multiple-swagger-api-endpoints-in-a-single-ui/.NETCombining multiple Swagger API endpoints in a single UIShifting from traditional monolithic application architecture to micorservices can solve bunch of problems and issues monolith application application design approach introduces, but on the other hand it has it's own drawbacks, although number of drawbacks compared to number of problems it solves is a lot greater so it makes sense to take a path in process of moving from monolithic to micorservices. On of the steps to move to micorservices is to physically have your services running as individual processesSun, 19 Apr 2020 01:02:13 -04002020-04-19T01:02:13-04:0024436https://dejanstojanovic.net/aspnet/2020/march/mocking-httpclient-in-unit-tests-with-moq-and-xunit/.NETMocking HttpClient in unit tests with Moq and Xunit when using IHttpClientFactory.NET Core has done a great job by introducing interface for most of classes which makes them easy to write unit tests around them. However, there are a lot of classes that re commonly used which are not refactored in .NET CoreThu, 12 Mar 2020 21:53:40 -04002020-03-12T21:53:40-04:0024427https://dejanstojanovic.net/aspnet/2020/march/overwriting-configuration-values-with-environment-variable-in-aspnet-core/.NETOverwriting configuration values with environment variable in ASP.NET CoreIt is obvious that no matter what is the size and complexity of your application, configuration values on your local development machine and the environment where the application is going to run will be different. To avoid any hard-coding and recompilation of your code, the most common practice is to store application and environment specific values to configuration filesMon, 02 Mar 2020 17:42:43 -05002020-03-02T17:42:43-05:0024422https://dejanstojanovic.net/aspnet/2020/march/custom-signalr-hub-authorization-in-aspnet-core/.NETCustom SignalR hub authorization in ASP.NET CoreSignalR is number one choice for real-time communication between server and client. It implements several transports for communication between server and clientSun, 01 Mar 2020 04:43:38 -05002020-03-01T04:43:38-05:0024415https://dejanstojanovic.net/aspnet/2020/january/mocking-systemio-filesystem-in-unit-tests-in-aspnet-core/.NETMocking System.IO filesystem in unit tests in ASP.NET CoreWorking with file system operations like creating or deleting files and directories if quite often part of applications flow. Both .NET and .NET Core come with great out of the box classes and methods to achieve this. These classes and methods are part of System.IO name space, but unfortunately both .NET and .NET Core implementations are the same and they use static classes and method to manipulate files and directories on the host file system. Thu, 09 Jan 2020 08:12:20 -05002020-01-09T08:12:20-05:0024405https://dejanstojanovic.net/powershell/2020/january/generation-java-client-libraries-for-rest-service-with-swagger-gen-azure-devops/PowerShellGeneration Java client libraries for REST service with swagger-gen Azure DevOpsGenerating client libraries for REST API which are documented with Swagger can significantly reduce product development time, especially on the front-end side. Well documented API can be easily interpreted by various tools to generate language specific libraries which can be then just easily integrated in in the API service consuming application. Some time ago I wrote an article Stop writing clients in C# for your Web APIs which explains how to use NSwag to generate NuGet packages for Swagger documented Web API REST services and to push them to Azure DevOps Artifact FeedWed, 08 Jan 2020 04:29:01 -05002020-01-08T04:29:01-05:0024396https://dejanstojanovic.net/aspnet/2019/november/using-options-pattern-in-mvc5-legacy-applications/.NETUsing options pattern in MVC5 legacy applications with web.configThe story behind New descendant of .NET Framework, .NET Core, comes with one really useful pattern for reading and using configuration files. It comes with out of the box support for JSON configuration files which are much more readable and give much greater freedom and flexibility on how to organize your settingsThu, 28 Nov 2019 05:07:52 -05002019-11-28T05:07:52-05:0024385https://dejanstojanovic.net/aspnet/2019/october/ignoring-properties-from-controller-action-model-in-swagger-using-jsonignore/.NETIgnoring properties from controller action model in Swagger using JsonIgnoreWhile designing the REST API, quite often you may find yourself in a situation where the data can be provided from multiple sources, like route, query string or POST/PUT payload. While that might not be a big problem, it may force you to redesign your models and most likely you will end up with keeping your original DTOs but then designing a new model in your application services layer just to have all your data from different sources in one place when you are passing it to the service method. Resolving multiple sources custom binding Sat, 26 Oct 2019 02:49:08 -04002019-10-26T02:49:08-04:0024379https://dejanstojanovic.net/aspnet/2019/october/increase-service-resilience-using-polly-and-retry-pattern-in-aspnet-core/.NETIncrease service resilience using Polly and retry pattern in ASP.NET CoreWhether you are doing micro-services or mid-size monolith applications that do not have to be too distributed, there is a big chance that you will depend on some external HTTP service. Whether it is REST, SOAP or any other type of the response, your application flow depends on it's response. Sure using queues and event-based communication between services or components will definitely increase the resilience of the application and make more error-proof, it adds additional complexity to the whole solution and sometimes that can be an overhead depending on the application type or the infrastructure you might be limited with. Tue, 15 Oct 2019 00:49:23 -04002019-10-15T00:49:23-04:0024377https://dejanstojanovic.net/aspnet/2019/october/strongly-typed-configuration-sections-with-options-pattern-in-aspnet-core/.NETStrongly typed configuration sections with options pattern in ASP.NET CoreConfiguration is probably the most essential part of every application, yet we do not give much attention to it during application design and development. .NET Core has quite nice way to store configurations (usually JSON files) and already built-in extensions to access configuration values and directly cast them to a specific typeTue, 01 Oct 2019 17:12:39 -04002019-10-01T17:12:39-04:0024368https://dejanstojanovic.net/aspnet/2019/september/unit-testing-repositories-in-aspnet-core-with-xunit-and-moq/.NETUnit testing repositories in ASP.NET Core with xUnit and MoqUnit testing is an important part for maintaining code quality and what is the most important thing, avoiding bugs in production. This is one of the reasons why unit tests and high code coverage is desired as a part of the project and as a part of the build process since you can detect potential bugs and issues during the build process when unit tests are executedTue, 10 Sep 2019 20:11:27 -04002019-09-10T20:11:27-04:0024351https://dejanstojanovic.net/aspnet/2019/september/mixed-model-binding-in-aspnet-core-using-custom-model-binders/.NETMixed model binding in ASP.NET Core using custom model bindersPatterns, conventions and standards are invented and enforced in order to make coding easier and more understandable for the developers, but in some cases certain patterns and conventions do not couple so easily and you have to rely on more on the actual technology you are using in order to overcome these complications. One of the cases this happens is using CQRS, especially commands and RESTWed, 04 Sep 2019 04:00:10 -04002019-09-04T04:00:10-04:0024345https://dejanstojanovic.net/powershell/2019/september/cloning-windows-virtual-machine-in-azure-without-having-to-stop-it/PowerShellCloning Windows Virtual Machine in Azure without having to stop itCreating a copy of an existing Virtual Machine on Azure is not really that much straight forward as you might think. The proper way as described in the documentation is to "generalize" Virtual Machine which puts it into a state where it can be used as a template for creating new Virtual MachinesMon, 02 Sep 2019 00:34:21 -04002019-09-02T00:34:21-04:0024337https://dejanstojanovic.net/aspnet/2019/august/handling-file-uploads-in-swagger-ui-with-aspnet-core/.NETHandling file uploads in Swagger UI with ASP.NET CoreSwagger is the most convenient way to document your REST api endpoints. It provides generating of documentation on the fly based on the code structure, which shortens the time of creating the documentation drasticallySat, 31 Aug 2019 16:43:02 -04002019-08-31T16:43:02-04:0024335https://dejanstojanovic.net/aspnet/2019/august/monitoring-redis-key-events-in-net-core/.NETMonitoring Redis key events in .NET CoreSome time ago I wrote an article about Reloading the cache automatically once expired is ASP.NET MVC. The piece of code represented in that article is build on top of .NET Framework 4.7.2Wed, 28 Aug 2019 17:07:54 -04002019-08-28T17:07:54-04:0024317https://dejanstojanovic.net/aspnet/2019/june/deploying-net-core-webjobs-to-azure-using-azure-build-pipeline/.NETDeploying .NET Core WebJobs to Azure using Azure Build PipelineAzure WebJobs are a great way to run background processes for your Web application on hosted on Azure WebApp. Althought Microsoft does not yet provide Visual Studio project templates for .NET Core (it only has built in project template for .NET framework 4.x) it is still possible to develop WebJob using .NET Core and run in on a WebAppWed, 12 Jun 2019 06:34:37 -04002019-06-12T06:34:37-04:0024309https://dejanstojanovic.net/aspnet/2019/june/writing-azure-webjobs-with-dependency-injection-net-core/.NETWriting Azure WebJobs with dependency injection in .NET Core WebJobs are a great way to run recurrent background tasks that support your application. They come as a part of Azure App Service/Web App serverless modelTue, 11 Jun 2019 02:29:01 -04002019-06-11T02:29:01-04:0024298https://dejanstojanovic.net/aspnet/2019/june/stop-writing-clients-in-c-for-your-web-apis/.NETStop writing clients in C# for your Web APIsTimes of writing your HttpClient setup to call REST API endpoint are over. It is just to much of repetitive code and taking care of the endpoints of the REST API serviceWed, 05 Jun 2019 14:04:19 -04002019-06-05T14:04:19-04:0024283https://dejanstojanovic.net/aspnet/2019/may/publishing-code-analysis-to-sonarcloud-from-azure-build-pipeline/.NETPublishing .NET Core code analysis to SonarCloud from Azure build pipelineCode analysis is and important part of application development. It can point to a potential bottle necks or code cluttering during the development processSun, 26 May 2019 10:53:43 -04002019-05-26T10:53:43-04:0023282https://dejanstojanovic.net/aspnet/2019/may/using-dispatcher-class-to-resolve-commands-and-queries-in-aspnet-core/.NETUsing dispatcher class to resolve CQRS commands and queries in ASP.NET CoreRecently I wrote an article about Automatic CQRS handler registration in ASP.NET Core with reflection in order to reduce number of lines for registering command and query to IOC container in ASP.NET Core. However, this solution does reduce lines for service registration in the startup, you still need to add all command and query handlers as parameters to the controller constructor. Tue, 21 May 2019 11:51:20 -04002019-05-21T11:51:20-04:0023281https://dejanstojanovic.net/aspnet/2019/may/automatic-cqrs-handler-registration-in-aspnet-core-with-reflection/.NETAutomatic CQRS handler registration in ASP.NET Core with reflectionCommand Query Responsibility Segregation (CQRS) pattern is one of my favorite way of handling the Web API requests for a simple reason that is clearly separates reading and writing. Quite often at some stage of the project you will hit the performance bottlenecks which are most probably cause by the way you are reading ow writing your data. CQRS splits reading and writing so that you can independently use different persistence framework for reading and writingSun, 19 May 2019 11:56:00 -04002019-05-19T11:56:00-04:0022274https://dejanstojanovic.net/aspnet/2019/april/localization-of-the-dtos-in-a-separate-assembly-in-aspnet-core/.NETLocalization of the DTOs in a separate assembly in ASP.NET CoreSince REST services do not have the UI, there is not much space for the localization. Data is sent and retrieved and most of the decisions is made based on the status code of the responseTue, 16 Apr 2019 08:13:30 -04002019-04-16T08:13:30-04:0022265https://dejanstojanovic.net/aspnet/2019/april/displaying-azure-devops-build-number-in-swagger-ui-for-aspnet-core/.NETDisplaying Azure DevOps build number in Swagger UI for ASP.NET CoreSwagger is a great way to document you REST API endpoints and reduce the need for communication, item spent and the cost for supporting the consumers of you APIs. Apart from providing the info about the endpoints, models, validation it can also display the data of the productSun, 14 Apr 2019 04:27:06 -04002019-04-14T04:27:06-04:0022262https://dejanstojanovic.net/aspnet/2019/april/why-you-should-not-use-authorize-attributes-to-protect-your-api-endpoints/.NETWhy you should not use Authorize attributes to protect your API endpointsAuthentication is an essential component of pretty much any REST API. Most of the resources you expose through REST API services, unless they are protected inside intranet, need to be protected by some kind of authentication. This is pretty much clear and it is easy achieved by just simply decorating your controller actions or even whole controllers with Authorize or AllowAnonymous attributes.  Mon, 08 Apr 2019 01:57:21 -04002019-04-08T01:57:21-04:0022260https://dejanstojanovic.net/aspnet/2019/march/dto-comments-from-external-assembly-in-swagger-documentation-in-aspnet-core/.NETDTO comments from external assembly in Swagger documentation in ASP.NET CoreContracts, models or DTOs, call them how ever you want, are your connection with the outside world from your REST API. Consumers of your API depend on them and they know what to expect or what your API endpoints expect in communicationTue, 26 Mar 2019 01:21:13 -04002019-03-26T01:21:13-04:0022259https://dejanstojanovic.net/aspnet/2019/march/partial-update-with-patch-using-dtos-and-automapper/.NETPartial update with PATCH using DTOs and AutoMapper in REST WebApiImplementing partial updates on the REST API is probably the trickiest method to implement. Unlike PUT HTTP method where you pass the whole DTO when you are updating an entity, PATCH method is intended to update only one or few properties of the entity you want to apply change toSat, 23 Mar 2019 02:16:12 -04002019-03-23T02:16:12-04:0022256https://dejanstojanovic.net/aspnet/2019/march/managing-images-on-filesystem-using-repository-pattern-in-net-core/.NETManaging images on filesystem using Repository pattern in .NET CoreIt is not uncommon that for records in database you need to store image files or other documents related to the specific record on the file system. Storing documents related to the database records on the file system is not a silver bulletTue, 12 Mar 2019 11:45:34 -04002019-03-12T11:45:34-04:0022247https://dejanstojanovic.net/aspnet/2019/february/reading-coordinates-from-the-photo-in-net-core/.NETReading coordinates from the photo in .NET CorePretty much all models of digital cameras including smartphones have ability and usually by default store additional metadata along with the image itself taken. This data is stored in EXIF format and you can easily see it if you are a Windows user by checking the properties of the photography file.   Mon, 25 Feb 2019 06:31:51 -05002019-02-25T06:31:51-05:0022242https://dejanstojanovic.net/aspnet/2019/february/making-reflection-in-net-work-faster/.NETMaking reflection in .NET Core work fasterReflection allows accessing type structure and its meta-data in runtime. Using reflection, you can dynamically instantiate objects, access fields, methods and properties regardless of the protection levelThu, 21 Feb 2019 06:32:53 -05002019-02-21T06:32:53-05:0022228https://dejanstojanovic.net/aspnet/2019/february/how-to-have-a-rest-with-azure-serverless/.NETHow to have a REST with Azure serverless functionsServerless model is becoming more and more popular everyday and all major cloud providers like AWS, Azure and GoogleCloud are  providing their own implementation of serverless cloud computing model. As more and more companies are shifting their infrastructure to cloud, serverless model becomes more and more popular mostly because it's cost effectiveness, easy setup and out of the box scaling and orchestrationMon, 04 Feb 2019 07:48:05 -05002019-02-04T07:48:05-05:0022218https://dejanstojanovic.net/aspnet/2019/january/mp3-to-text-using-azure-cognitive-services/.NETSpeech to text mp3 audio files using Azure Cognitive Services and .NET CoreThere is a big buzz about AI these days and major Cloud vendors like Amazon Web Services, Azure, Google Cloud are competing to bring better products to their platforms for variety of AI tasks. One of these services is speech recognition and generating transcription text from the audio. I recently worked on a project which involved transcribing large amount of daily generated audio recordingsMon, 21 Jan 2019 05:09:13 -05002019-01-21T05:09:13-05:0022214https://dejanstojanovic.net/aspnet/2019/january/sqlbulkcopy-object-collection-to-database-table-with-c/.NETSqlBulkCopy object collection to database table with C#Over the time various techniques to manipulate database data have evolved in .NET. Entity Framework is certainly the most advanced one, but for small ad hock applications where you have few inserts to deal with, ADO is still the fastest way to write data to the databaseFri, 04 Jan 2019 02:06:00 -05002019-01-04T02:06:00-05:0022206https://dejanstojanovic.net/aspnet/2019/january/filtering-and-paging-in-aspnet-core-web-api/.NETFiltering and paging collection result in ASP.NET Core Web APIPaging a REST API response is equally important as filtering the data returned through REST API endpoints and they quite often come together. Just like filtering, paging limits the amount of data returned from the endpoint, saving both client and server side resourcesThu, 03 Jan 2019 02:40:02 -05002019-01-03T02:40:02-05:0022199https://dejanstojanovic.net/aspnet/2018/december/running-net-core-on-raspberry-pi-with-raspbian-stretch/.NETRunning .NET Core on Raspberry PI with Raspbian StretchApart from running on Windows and Linux both x86 and x64 architecture, .NET Core is an ideal platform for IOT (Internet of things) projects because it can also run on ARM32 and ARM64. This means you can run it pretty much any device with both RISC or CISC processor architecture. If you are .NET developer or you are familiar with .NET platform and C# language, this means you can now write applications that run on Raspberry Pi which is based on RISC architecture by writing them in Visual StudioSun, 30 Dec 2018 12:52:32 -05002018-12-30T12:52:32-05:0022198https://dejanstojanovic.net/aspnet/2018/december/choosing-the-proper-return-type-for-webapi-controller-actions/.NETThe best option to use for a return type in ASP.NET Core WebAPI controllerStarting from .NET Core version 2.1, there are so far three types of WebApi responses that controller actions can return. All three types had it's own pros and cons but all are lacking in options to satisfy both REST and the high level of testability.  The available response types in ASP.NET Core including recently released 2.2 version are Sat, 15 Dec 2018 23:35:57 -05002018-12-15T23:35:57-05:0022187https://dejanstojanovic.net/aspnet/2018/december/registering-multiple-implementations-of-the-same-interface-in-aspnet-core/.NETRegistering multiple implementations of the same interface in ASP.NET CoreStarting from it's initial release ASP .NET Core comes with built in dependency injection (DI) to help implement Inversion Of Control design pattern. This is not something new in .NET and apart from built-in DI in .NET Core, there are other libraries which provide same and in some cases even more advanced dependency injection implementationSat, 08 Dec 2018 10:52:46 -05002018-12-08T10:52:46-05:0022186https://dejanstojanovic.net/aspnet/2018/december/setting-up-kestrel-port-in-configuration-file-in-aspnet-core/.NETSetting up Kestrel port in configuration file in ASP.NET CoreWhen running ASP.NET Core application as self-hosted using Kestrel, it will by default use port 5000 for listening for requests. This should not be a big issue since you can always proxy requests to port 5000. Problem occurs when you might want to have multiple applications on one host, or you simply cannot use port 5000 for security or any other reasons.Luckily, default port for ASP.NET Core application running on Kestrel can be easily changed, but in order to make it easily configurable there are few changes you need to make in your code in order to access IHostingEnvironment and IConfiguration implementation instances combined. Wed, 05 Dec 2018 07:30:23 -05002018-12-05T07:30:23-05:0022180https://dejanstojanovic.net/aspnet/2018/november/using-displayname-attribute-for-model-validation-output-in-aspnet-mvc-core/.NETUsing DisplayName attribute for model validation output in ASP.NET MVC CoreModel validation is an important part of request life-cycle and pipeline in MVC Core regardless whether you are building Web API project or ASP.NET MVC web application. Both project templates rely on the common ASP.NET Core platform therefore validation is pretty much the same in both type of projects. Because Web API and micro services are more popular nowadays, I am going to use Web API sample project to demonstrate how to modify validation response in MVC Web API Core project. Wed, 28 Nov 2018 06:25:11 -05002018-11-28T06:25:11-05:0022179https://dejanstojanovic.net/aspnet/2018/november/dependency-injection-with-custom-mvc-filter-attributes-in-aspnet-core/.NETDependency injection with custom MVC filter attributes in ASP.NET Core Apart from adding your own middleware to the ASP.NET MVC Core application pipeline, you can control the response using custom MVC filter attributes and selectively apply them to either whole controller or controller actions. One of the commonly used MVC filter in ASP.NET Core is ExceptionFilterAttribute for handling error response in Wep API applications. It is easy to implement and I also wrote an article about Error handling in ASP.NET Core Web API few months agoSun, 25 Nov 2018 05:04:31 -05002018-11-25T05:04:31-05:0022176https://dejanstojanovic.net/powershell/2018/november/install-multiple-packages-from-visual-studio-package-manager-console/PowerShellInstall multiple packages from Visual Studio package manager consoleIf you are using Visual Studio 2017 as your main IDE, than you are probably familiar and used at least once NuGet package manager console. You may know or maybe not, but NuGet Package Manager relies on PowerShell script and Package Manager Console is basically hosted PowerShell command line inside Visual Studio. This means, apart from NuGet commands, you can also execute PowerShell commands.  Thu, 22 Nov 2018 06:55:24 -05002018-11-22T06:55:24-05:0022170https://dejanstojanovic.net/aspnet/2018/november/adding-healthchecks-just-got-a-lot-easier-in-aspnet-core-22/.NETAdding healthchecks just got a lot easier in ASP.NET Core 2.2 Health checks or health probes are the crucial part for orchestrating micro services. If you are using Kubernetes for orchestrating containerized application instances or you just have multiple ServiceApps or VMS behind the load balancer, you need to define health checks in order for the orchestrator or load balancer to know to which instance to send the traffic and to which notWed, 21 Nov 2018 10:19:48 -05002018-11-21T10:19:48-05:0022169https://dejanstojanovic.net/aspnet/2018/november/mocking-iconfiguration-getvalue-extension-methods-in-unit-test/.NETMocking IConfiguration GetValue<T> extension methods in Unit TestNow here is a trouble that was bugging me for some time and I guess who ever is using IConfigration injected in the constructor and using extension methods to access configuration values reached whan trying to write Unit Tests. IConfiguration interface is a great way to easily replace your configuration layer in application, but it has it's drawbacks. The way interface envorces configuration reading is by exposing GetSection method which return IConfigurationSectionTue, 20 Nov 2018 07:46:07 -05002018-11-20T07:46:07-05:0022168https://dejanstojanovic.net/aspnet/2018/november/tracking-data-changes-with-entity-framework-core/.NETTracking data changes with Entity Framework CoreTracing data changes can be beneficial in narrowing down the issue that may occur in production. If you are using Entity Framework Core you have several ways to store actions performed against your dataTue, 13 Nov 2018 23:57:36 -05002018-11-13T23:57:36-05:0022167https://dejanstojanovic.net/aspnet/2018/november/handling-data-concurrency-in-ef-core-and-aspnet-core-webapi/.NETHandling data concurrency in EF Core and ASP.NET Core WebAPIEntity Framework Core implements optimistic concurrency strategy which is opposite to pessimistic concurrency strategy. Lets's first clear out what are main differences between these two approaches in concurrency control. Optimistic concurrency control allows multiple processes to access and modify data without any explicit lock on the dataSun, 11 Nov 2018 06:00:41 -05002018-11-11T06:00:41-05:0022162https://dejanstojanovic.net/aspnet/2018/november/setting-up-swagger-to-support-versioned-api-endpoints-in-aspnet-core/.NETSetting up Swagger to support versioned API endpoints in ASP.NET CoreVersioning of your endpoints is important especially if you have 3rd party dependent clients of your REST API service. Any change in your endpoint, for example in data structure may impact clients even if it is backward compatible, clients may process your endpoint data in different ways, so even adding one additional property to your model may also impact functionality of the client which is consuming your endpoint. Prerequisites Sun, 04 Nov 2018 02:24:46 -05002018-11-04T02:24:46-05:0022158https://dejanstojanovic.net/javascript/2018/october/html5-localstorage-with-expiry-with-vanilla-javascript/JavaScriptHTML5 localStorage with expiry with vanilla JavaScriptHTML5 comes with a lot of handy features which can really improve user experience of your web application significantly if you use them wisely. Caching cold data on the client, such as lookups can significantly save the amount of traffic, page load time and even you backed services load. One of the HTML5 features that can help you do this are sessionStorage and localStorageSun, 28 Oct 2018 02:54:15 -04002018-10-28T02:54:15-04:0022150https://dejanstojanovic.net/aspnet/2018/october/extending-serilog-with-additional-values-to-log/.NETExtending Serilog with additional values to logIf you are building .NET Core application your choice for logger library is most likely Serilog. It is really powerful and easy to use library which allows you easy logging in all levels in your application. One of the best features it has is easy extending of the data you want to have in your logsWed, 10 Oct 2018 02:56:59 -04002018-10-10T02:56:59-04:0022149https://dejanstojanovic.net/aspnet/2018/october/logging-ef-core-actions-to-a-file-using-serilog/.NETLogging EF Core actions to a file using SerilogLogging is an essential part of the application. It gives you insights which allows you to see your application behavior or even user behaviour and actions taken by them in the application.Serilog is most probably the most popular library for logging in .NET Core applicationsMon, 08 Oct 2018 11:39:36 -04002018-10-08T11:39:36-04:0022144https://dejanstojanovic.net/containers/2018/september/different-ways-to-auto-generate-docker-image-tags/DockerDifferent ways to auto-generate Docker image tagsTagging Docker images is important to keep track of versions of the service running and to easily roll back in case of faulty behavior of the application. The version strategy which is the most clear and understandable is tagging image with version of the application for example Thu, 20 Sep 2018 02:47:00 -04002018-09-20T02:47:00-04:0022138https://dejanstojanovic.net/aspnet/2018/september/custom-input-and-output-serializers-in-aspnet-core/.NETUsing custom request and response serializers in ASP.NET CoreThis is not a new subject and the support for handling WebApi input and output was introduced in .NET Core 2.0 and it's been there since then. There are couple of useful pages out there and it is even well documented on Microsoft official page Custom formatters in ASP.NET Core Web APISun, 16 Sep 2018 07:59:16 -04002018-09-16T07:59:16-04:0022133https://dejanstojanovic.net/aspnet/2018/september/setting-up-net-core-development-environment-on-ubuntu-linux/.NETSetting up .NET Core development environment on Ubuntu LinuxWith growing popularity of dotnet Core, Git and Docker, developers who used to work mainly on Windows are now getting used to CLI environment and obviously Linux. Windows is still a development environment platform of choice, bit since Microsoft already developed and published Visual Studio Code as a cross platform IDE for Windows, Linux and Mac. Although it is still not mature as Visual Studio 2017, it is a decent tool for .NET Core applications developmentTue, 11 Sep 2018 02:47:28 -04002018-09-11T02:47:28-04:0022132https://dejanstojanovic.net/aspnet/2018/september/reloading-the-cache-automatically-once-expired-is-aspnet-mvc/.NETReloading the cache automatically once expired is ASP.NET MVCIn memory caching is not a bullet proof way of caching data in an application, especially if this application is distributed. The lack of synchronization between nodes can cause you application to misbehave showing wrong data or even throwing exceptions and crashing. This is one of the main reasons why distributed caching is the best way of doing the caching in your web application. But not all applications you might be developing need to run as distributed on multiple machinesSat, 08 Sep 2018 12:22:05 -04002018-09-08T12:22:05-04:0022131https://dejanstojanovic.net/containers/2018/september/simple-script-for-building-and-publishing-net-core-application-to-docker/DockerSimple script for building and publishing .NET Core application to DockerRecently I wanted to try to spin up a simple .NET Core application on my local cluster which I built in my previous article Manual setup of Kubernetes cluster on a Virtual Machine with kubeadm. The problem I had is that I needed to test applications in this cluster and deploy them as service in order to monitor potential issues behavior. As deployment of Kubernetes service needs an image to pull from, I decided to use dockerhub to push my test images, but they first needed to be created. Fri, 07 Sep 2018 02:05:21 -04002018-09-07T02:05:21-04:0022119https://dejanstojanovic.net/aspnet/2018/august/get-most-visited-pages-of-your-website-from-google-analytics-using-c/.NETGet most visited pages of your website from Google Analytics using C#If you have a website like this one with articles and you would like to suggest most visited articles to your visitors, there are few ways to do this. One of them is definitely a custom solution that can track and store count of every visit per page you have, or without any re-inventing of wheel you can just hook to Google Analytics API to pull the dataMon, 27 Aug 2018 12:42:01 -04002018-08-27T12:42:01-04:0022115https://dejanstojanovic.net/aspnet/2018/august/creating-windows-service-and-linux-daemon-with-the-same-code-base-in-net/.NETCreating Windows service and Linux daemon with the same code base in .NETFew months back I wrote an article on how to create Linux daemon in .NET Core using generic host class introduced in 2.1 version of .NET Core. This code works just great on Linux OS when configured as a daemon in systemd and provides more less same concept you would have with Windows Service written in .NET Framework 4.x. The code works just fine on both Windows and Linux hosts, but because it is compiled as a Console Application, you do not really get to run it on your Windows machine as a ServiceSun, 26 Aug 2018 04:31:16 -04002018-08-26T04:31:16-04:0022109https://dejanstojanovic.net/containers/2018/august/manual-setup-of-kubernetes-cluster-on-a-virtual-machine-with-kubeadm/DockerManual setup of Kubernetes cluster on a Virtual Machine with kubeadmKubernetes is one of the most popular container orchestrator. It is platform agnostic and although it uses Docker as its default container engine it can also run on Rocket developed by Core OS teamThu, 23 Aug 2018 02:42:05 -04002018-08-23T02:42:05-04:0022102https://dejanstojanovic.net/aspnet/2018/august/minify-aspnet-mvc-core-response-using-custom-middleware-and-pipeline/.NETMinify ASP.NET MVC Core response using custom middleware and pipelineFor my website, since it runs on Umbraco 6 and it is basically ASP.NET MVC application. To reduce load time and increase website performances I decided to alternate the response of the application and minify it using simple regular expression. Initially I was trying to do this with YUI Compressor library which has .NET port as NuGet YUICompressor.NET which works fine in most of the cases, but in my case does not skip PRE tags which I use for code snippets on the websiteTue, 14 Aug 2018 06:26:05 -04002018-08-14T06:26:05-04:0022099https://dejanstojanovic.net/aspnet/2018/august/background-working-scheduled-task-in-aspnet-core-mvc-application/.NETBackground working scheduled task in ASP.NET Core MVC applicationCaching common data like lookups for example in memory of your app can increase significantly your MVC web application performances and response time. Of course this data has to be periodically refreshed. You can use various approaches to refresh data including expiry, but this can create potential bottle necks in your application since once data expires, you will use request thread to pull the data, cache and serve the request response backThu, 09 Aug 2018 03:20:05 -04002018-08-09T03:20:05-04:0022095https://dejanstojanovic.net/aspnet/2018/august/simple-pixel-conversion-tracking-implementation-on-aspnet-core-webapi/.NETSimple pixel conversion tracking implementation in ASP.NET Core WebApiPixel tracking, although it is the oldest method for tracking conversions in marketing, it is still used widely and some big companies like Facebook are still overing it as one of the methods for tracking the conversions of on your web pages. Tracking conversion via pixel method is still widely used because of it's simplicitySat, 04 Aug 2018 10:06:53 -04002018-08-04T10:06:53-04:0022094https://dejanstojanovic.net/aspnet/2018/august/limit-number-of-tasks-running-in-parallel-in-net/.NETLimit number of tasks running at the same time in .NETLimiting the number concurrently running Tasks is not that often requirement in a code, but eventually you'll find yourself in the situation that for the most likely performance issues you'll have to limit number of concurrently running Tasks. One of these situations is when you have long running operations in the Task. If you spin up to many Tasks you will seriously degrade your application performanceFri, 03 Aug 2018 14:24:50 -04002018-08-03T14:24:50-04:0022081https://dejanstojanovic.net/aspnet/2018/july/request-filtering-in-aspnet-core-using-middleware-and-request-pipeline/.NETRequest Filtering in ASP.NET Core using Middleware and request pipelineASP.NET Core comes with advanced request processing thrugh pipepline configuretion of the .NET Core middleware elements. You can easily specify the steps that will be exscuted on the request object all the way until the response is returned backThu, 26 Jul 2018 15:51:14 -04002018-07-26T15:51:14-04:0022078https://dejanstojanovic.net/aspnet/2018/july/how-to-get-client-ip-address-in-aspnet-core-2/.NETHow to get client IP Address in ASP.NET Core 2As ASP.NET was evolving, there were different ways accessing client IP address from the request. The way to do it WebForms and MVC Web application is simply accessing request of the current HTTP context Fri, 06 Jul 2018 04:04:27 -04002018-07-06T04:04:27-04:0022075https://dejanstojanovic.net/aspnet/2018/july/differences-in-time-zones-in-net-core-on-windows-and-linux-host-os/.NETDifferences in Time Zone Formats in .NET Core on Windows and Linux hostRecently I was working on converting DateTime value to a different time zone because the servers are running in a different time zone than the database where data is stored. Storing DateTime values in UTC time zone is the best practice, so simple DateTime.ToUniversalTime method call solves the problemTue, 03 Jul 2018 10:43:47 -04002018-07-03T10:43:47-04:0022072https://dejanstojanovic.net/aspnet/2018/july/different-ways-to-set-environment-for-net-core-application/.NETDifferent ways to set environment variable for .NET Core application.NET Core comes with a great feature for loading different config file based on the environment. Environment is picked up from the host environment variables whether that is Windows on Linux based OSMon, 02 Jul 2018 00:54:19 -04002018-07-02T00:54:19-04:0022069https://dejanstojanovic.net/aspnet/2018/june/building-advanced-net-core-global-tool/.NETBuilding advanced .NET Core Global Tool using CommandLineUtils packageMicrosoft introduced a new feature called Global Tool with the new .NET Core release 2.1. Essentially, global tools are simple console applications which can be invoked from the consoleWed, 27 Jun 2018 06:56:41 -04002018-06-27T06:56:41-04:0022068https://dejanstojanovic.net/aspnet/2018/june/generate-c-models-from-protobuf-proto-files-directly-from-visual-studio/.NETGenerate C# models from Protobuf proto files directly from Visual StudioI wrote about boosting performances by choosing the right serialization in .NET projects. The top best performing according to my tests and many of the online comparisons are Apache Avro and Google Protocol Buffer (Protobuf) serializationMon, 25 Jun 2018 13:34:42 -04002018-06-25T13:34:42-04:0022067https://dejanstojanovic.net/aspnet/2018/june/loading-rsa-key-pair-from-pem-files-in-net-core-with-c/.NETLoading RSA key pair from PEM files in .NET Core with C#Recently I wrote and article about using asymmetric keys for token based authentication in ASP.NET Core. As I was setting up the RSA keys to test the demo appliation I kept running to some challanges that did not make thigs going so smooth Challenge number 1 - OpenSSL Sun, 24 Jun 2018 04:00:25 -04002018-06-24T04:00:25-04:0022065https://dejanstojanovic.net/aspnet/2018/june/token-based-authentication-in-aspnet-core-part-3/.NETToken based authentication and Identity framework in ASP.NET Core - Part 3Recently I wrote about setting up .NET Core Identity Framework and Token based authentication in ASP.NET Core using symmetric key signing. The downside of this approach is that both identity and resource server share the same key for signing and validating the tokenThu, 21 Jun 2018 11:39:33 -04002018-06-21T11:39:33-04:0022053https://dejanstojanovic.net/aspnet/2018/june/token-based-authentication-in-aspnet-core-part-2/.NETToken based authentication and Identity framework in ASP.NET Core - Part 2In article Token based authentication and Identity framework in ASP.NET Core - Part 1 I described how to setup identity library for storing user accounts. Now we are going to setup ASP.NET Core Web API project to issue the token for authenticated users so they can access protected resources. Identity Web API instance will be separated from from the resource Web API, so we'll have eventually two and possibly in future more resource services which will all use single identity server fr authentication and issuing access tokens. Wed, 20 Jun 2018 00:46:57 -04002018-06-20T00:46:57-04:0022052https://dejanstojanovic.net/aspnet/2018/june/token-based-authentication-in-aspnet-core-part-1/.NETToken based authentication and Identity framework in ASP.NET Core - Part 1In ASP.NET Core identity framework is introduced as a membership provider making user management, authentication and authorization. It is built on to Entity Framework Core ORM which allows you to be storage type independentWed, 20 Jun 2018 00:45:05 -04002018-06-20T00:45:05-04:0022044https://dejanstojanovic.net/powershell/2018/june/remote-powershell-core-session-to-a-linux-host-from-windows-machine/PowerShellRemote PowerShell Core session to a Linux host from Windows machineStarting from January 2018, Microsft has made PowerShell Core 6, a cross-platform tool available not only to Windows users which was the case so far with previous versions, but to Linux and Mac users as well. Since it was tool for Windows only, it had it's own ways for remoting using WinRM unlike Linux operating systems which primarily rely on SSH. Windows is great for editing and development, I find it really comfortable to work on with so many tools and platform availableMon, 18 Jun 2018 13:01:39 -04002018-06-18T13:01:39-04:0022043https://dejanstojanovic.net/aspnet/2018/june/sending-email-in-aspnet-core-using-smtpclient-and-dependency-injection/.NETSending email in ASP.NET Core using SmtpClient and dependency injectionStarting with .NET Core 2.0, Microsoft introduced SmtpClient, identical implementation as in .NET 4. This made sending emails from the application a lot easier as there is functionality out of the box and you do not have to rely on the 3rd party nuget packages. If you inspect this class, you will see that the only interface it inherits is IDisposable, so it does not give you many options for injection unless you wrap it with your own implementation and interface, but since we are not going to go that deep into the dependency injection, we'll just focus on creating a client instance using .NET Core dependency injection framework. Sun, 17 Jun 2018 03:44:15 -04002018-06-17T03:44:15-04:0022041https://dejanstojanovic.net/aspnet/2018/june/clean-service-stop-on-linux-with-net-core-21/.NETClean service stop by handling SIGTERM on Linux with .NET Core 2.1Some time ago I wrote about setting up .NET Core service/daemon on Linux. Back than I was using .NET Core 2.0 SDK on both development Windows machine and Linux host machineThu, 14 Jun 2018 13:00:47 -04002018-06-14T13:00:47-04:0021044https://dejanstojanovic.net/aspnet/2018/june/advanced-versioning-in-aspnet-core-web-api/.NETAdvanced versioning in ASP.NET Core Web APISome time ago I wrote an article about ASP.NET Core Web API versioning which describes route based Web API endpoint versioning. I love route versioning and to me it is the best way of versioning because it is pretty straight, but there are situations where this kind of versioning is not suitable. On nuget.org you can find Microsoft.AspNetCore.Mvc.Versioning package which gives you more options on how you can version your Web API endpointsWed, 13 Jun 2018 12:20:48 -04002018-06-13T12:20:48-04:0021041https://dejanstojanovic.net/aspnet/2018/june/use-different-configuration-based-on-environment-value-in-aspnet-core/.NETUse different configuration based on environment value in ASP.NET CoreIn .NET framework, having separate configuration is possible by having different web.config or app.config file transformations since in .NET framework configuration is stored in XML format. You can check more on this in article Separate configuration files per build config in Visual Studio IDEWed, 13 Jun 2018 06:31:40 -04002018-06-13T06:31:40-04:0021029https://dejanstojanovic.net/aspnet/2018/june/how-to-boost-application-performance-by-choosing-the-right-serialization/.NETHow to boost application performance by choosing the right serializationPretty much any serious application now days needs to interact with any storage media such as disk or network. This is where serialization comes inSun, 10 Jun 2018 05:21:25 -04002018-06-10T05:21:25-04:0021021https://dejanstojanovic.net/aspnet/2018/june/how-to-setup-aspnet-core-run-on-debian-linux-with-nginx/.NETHow to setup ASP.NET Core run on Debian Linux with NginxIn two previous articles (How to setup .NET Core 2 on Debian or Ubuntu Linux distro the easy way &amp; Setting up .NET Core service/daemon on Debian Linux OS) I explained how to setup and run .NET Core based applications and how to run them as a Linux daemon. In this article we are going to take it one step furtherTue, 05 Jun 2018 12:43:50 -04002018-06-05T12:43:50-04:0021016https://dejanstojanovic.net/aspnet/2018/june/setting-up-net-core-servicedaemon-on-linux-os/.NETSetting up .NET Core service/daemon on Debian Linux OSI found a lot of articles out here on this subject, but non of them actually made the daemon work from the first time. There was always some catch I had to chase and found in some other article posted online. In this article I will try to cover as much as possible how to setup .NET Core daemon working on a clean Debian 9 Linux machineFri, 01 Jun 2018 01:41:29 -04002018-06-01T01:41:29-04:0021013https://dejanstojanovic.net/aspnet/2018/may/the-fastest-way-to-setup-net-core-2-on-debian-or-ubuntu-linux-distro/.NETHow to setup .NET Core 2 on Debian or Ubuntu Linux distro the easy wayMany of you who had chance to work docker and .NET Cote on Linux will agree that easiest way of running .NET Core on Linux is to pull microsoft/aspnetcore:2.0 image from docker repository and just setup your app with .Dockerfile. You will be saved of the hassle of setting up the environment and .NET Core on on the Linux machine. But what if that is not an option? What if you really need for some reason to run your application on the specific host and not in the container? Wed, 30 May 2018 07:55:19 -04002018-05-30T07:55:19-04:0021009https://dejanstojanovic.net/aspnet/2018/may/google-invisible-recaptcha-and-recaptcha-v2-in-aspnet-core-web-applications/.NETGoogle Invisible reCAPTCHA and reCAPTCHA v2 in ASP.NET CoreRecently I wrote and article about setting up and using Google reCAPTCHA v2, better known as "I'm not a robot" validation. If you were setting up reCAPTCHA v2, you probably noticed that there is an option for "Invisible reCAPTCHA" option. This type of validation, instead of asking user to interact with the UI in order to be identified as a human, does not require any direct interaction which can help building better user experience for your visitorsTue, 29 May 2018 07:09:20 -04002018-05-29T07:09:20-04:0021001https://dejanstojanovic.net/aspnet/2018/may/using-google-recaptcha-v2-in-aspnet-core-web-application/.NETUsing Google reCAPTCHA v2 in ASP.NET Core Web Application In case you have any page on your website which allows anonymous users to POST data to your web application, you should always use any kind of bot protection. Usually that is any kind of CAPTCHA implementationThu, 24 May 2018 06:34:04 -04002018-05-24T06:34:04-04:0021000https://dejanstojanovic.net/aspnet/2018/may/redis-health-check-in-aspnet-core-webapi/.NETRedis health check in ASP.NET Core WebApiEven before popularity of micro service approach, for even monolithic applications you needed to have health-checks (Google Compute Engine) or health-probes (Microsoft Azure) for load balancing. Basically in load balancing scenario, these endpoints are used to tell load balancer whether instance can handle requests or not. Since handling of requests may consider several components, these endpoints either return 200 OK HTTP response or any other response like 500 Internal Server Error with optional payload message describing the issue and each component status. Wed, 23 May 2018 07:19:38 -04002018-05-23T07:19:38-04:0020999https://dejanstojanovic.net/aspnet/2018/may/using-idistributedcache-in-net-core-just-got-a-lot-easier/.NETUsing strongly typed objects with IDistributedCache instead of byte arraysSaving an object to distributed cache store in .NET Core requires your object to be serialized to byte array in order for SetAsync method on Microsoft.Extensions.Caching.Distributed.IDistributedCache interface implemented instance to save your object to the injected cache store instance. This means that what ever instance you have, you need to serialize it first to byte array. Similar, just reversed process applies for the process of reading an object from the distributed cache store. Tue, 22 May 2018 07:16:55 -04002018-05-22T07:16:55-04:0020996https://dejanstojanovic.net/aspnet/2018/may/seeding-data-in-entity-framework-core-from-visual-studio/.NETSeeding data in Entity Framework Core from Visual StudioUnlike Entity Framework 6, EF Core and whole .NET Core relies on dependency injection. For example, configuration is expected to be injected from the calling assembly instead of being available at any timeFri, 18 May 2018 06:24:15 -04002018-05-18T06:24:15-04:0020994https://dejanstojanovic.net/aspnet/2018/may/error-handling-in-aspnet-core/.NETError handling in ASP.NET Core Web APIBoth Web API in .NET 4.5 and later and Web API in ASP.NET CORE have great error handling support out of the box. You can specify you global handler and control your response to a client when exception happens. Tue, 15 May 2018 06:42:47 -04002018-05-15T06:42:47-04:0020993https://dejanstojanovic.net/aspnet/2018/may/setnx-with-ttl-in-net-using-stackexchangeredis/.NETSETNX with TTL in .NET using StackExchange.RedisRecently I needed to set redis key if it is not present with specific expiry time to use it as some logical flag. I knew tat you can use SETNX command for this but did not have any info how to set the expiry time. After some time going through redis documentation and articles found online I found a SET method overload for the redis-cli. Sun, 13 May 2018 03:22:47 -04002018-05-13T03:22:47-04:0020992https://dejanstojanovic.net/javascript/2018/may/monitoring-dom-changes-with-javascript/JavaScriptMonitoring DOM changes with JavaScriptIf you are dealing with pure JavaScript without using any library, you probably want to trigger your custom actions on some element event. This is easily done with addEventListener which is in general supported by all now days browsers.  Tue, 08 May 2018 08:28:42 -04002018-05-08T08:28:42-04:0020987https://dejanstojanovic.net/sql/2018/may/reading-json-data-in-t-sql-on-sql-server/SQL/T-SQLReading JSON data in T-SQL on SQL ServerJSON is the most commonly used data fromat nowdays. It is lighter than XML, more readable and it's sindax complies with most OOP C-Like lnguages such as Java, JavaScript and C#. There is not really many downsides of using JSON, so that is one of the rasons everyone is using it in one way or another. Thu, 03 May 2018 00:26:08 -04002018-05-03T00:26:08-04:0020984https://dejanstojanovic.net/aspnet/2018/may/generic-string-to-primitive-type-converter-in-c/.NETGeneric string to primitive type converter in C#Often case when you need to convert String to a different type which is most of the time a primitive type in C# is when you are reading values from configuration. In both .NET and .NET Core, reading from configuration return plain String valueWed, 02 May 2018 06:55:33 -04002018-05-02T06:55:33-04:0020982https://dejanstojanovic.net/aspnet/2018/april/simple-implementation-of-aspnet-web-api-basic-authentication-security/.NETSimple implementation of ASP.NET Web API Basic authentication securityAuthentication in web services is a bit more different than with web pages because of one simple reason. There is no UI for entering credentials to authenticate to consume serviceSat, 07 Apr 2018 03:14:14 -04002018-04-07T03:14:14-04:0020977https://dejanstojanovic.net/aspnet/2018/march/getting-gif-image-information-using-c/.NETGetting GIF image information using C#GIF image format is most commonly used format for online advertising, especially since all browser starting from major onces stopped supporting Flash animations because of their infamous security vulnerabilities and issues. After going through different articles I found online, I came up with the class which exposes following GIF image propertiesWed, 28 Mar 2018 07:30:25 -04002018-03-28T07:30:25-04:0020976https://dejanstojanovic.net/aspnet/2018/march/how-to-avoid-threadsleep-in-your-production-code-in-net/.NETHow to avoid Thread.Sleep in your production code in .NETI am pretty sure any of us used Thread.Sleep method to pause the current thread execution. Mostly this is used to simulate long running process during the test or debug. While this is fine to use for testing, if your intention is to actually schedule thread execution this is probably wrong way of doing it, simply because Thread.Sleep does not actually take as many milliseconds as you pass to the method as a parameterSun, 25 Mar 2018 07:10:14 -04002018-03-25T07:10:14-04:0019975https://dejanstojanovic.net/aspnet/2018/march/reduce-traffic-by-serializing-json-with-different-alias-with-jsonnet-and-c/.NETReduce traffic by serializing JSON with different alias with Json.NET and C#One of the reasons JSON is used rather than XML is it's simplicity in notation. However XML is claimed to be more human readable than JSON and JSON is easier to parse for machines, so basically we switched from XML in favor to machine processing. If you take a C# class and serialize it to JSON string you still find it quite readable since we kept all nice property names in the JSON outputFri, 23 Mar 2018 01:08:40 -04002018-03-23T01:08:40-04:0019970https://dejanstojanovic.net/aspnet/2018/march/log4net-logger-for-microsoft-azure-log-analytics/.NETlog4net logger for Microsoft Azure Log Analytics Recently I wrote an article on how to Send data to Azure Log Analytics from C# code which is demonstrating pushing data from your code to Microsoft Azure Log Analytics and simple quering the data from the Log Analytics. Azure Log Analytics are extremely helpful for storing application logs because they provide transformation of the raw data into queriable columns, you can easily query your logs stored in Log Analytics and export to Excel format if you need to share the data or you just want to make some offline data analysisSun, 18 Mar 2018 07:51:33 -04002018-03-18T07:51:33-04:0019963https://dejanstojanovic.net/powershell/2018/march/setting-ip-address-and-domain-filtering-in-iis-using-powershell-script/PowerShellSetting IP address and domain filtering in IIS using PowerShell scriptStarting from IIS 7.0 Microsoft introduced IP and Domain restrictions feature as a part of IIS setup. However, if you do not have this feature installed on your IIS you can easily install it through windows features adding steps which are pretty much same for each Windows version (https://docs.microsoft.com/en-us/iis/configuration/system.webserver/security/ipsecurity/add) or simply by using WebPlatform Installer. Just run WebPlatform Installer and search for IP and Domain restrictions in search boxSat, 17 Mar 2018 06:35:05 -04002018-03-17T06:35:05-04:0019962https://dejanstojanovic.net/aspnet/2018/march/download-file-in-chunks-in-parallel-in-c/.NETDownload file in chunks in parallel in C#Downloading large files  from your code may cause problems due to limitations in your network or system where your code is executing. For example, some systems limit the size of the file you can download through the networkWed, 14 Mar 2018 13:03:43 -04002018-03-14T13:03:43-04:0019955https://dejanstojanovic.net/aspnet/2018/march/displaying-multiple-select-input-for-enum-in-swagger-webapi-ui/.NETDisplaying multiple select input for Enum in Swagger WebApi UIEnums in C# can contain multiple values if they are decorated with [Flags] attribute. However, Flag Enums are not recommended to be used in web api action method signaturesTue, 13 Mar 2018 11:35:52 -04002018-03-13T11:35:52-04:0019946https://dejanstojanovic.net/aspnet/2018/march/handling-cross-site-scripting-xss-in-aspnet-mvc/.NETHandling Cross-Site Scripting (XSS) in ASP.NET MVCCross-site Scripting (XSS) refers to client-site code injection attack where an attacker can execute malicious scripts into a web application. Basically attacker manages to upload malicious script code to the website which will be later on served to the users and executed in their browserThu, 08 Mar 2018 14:05:07 -05002018-03-08T14:05:07-05:0019945https://dejanstojanovic.net/aspnet/2018/march/using-webp-images-in-apsnet-with-a-fallback-to-jpeg-and-png/.NETUsing WebP Images in APS.NET with a fallback to JPEG and PNGWebP is an image format introduced by Google Developers and it provides superior lossless and lossy compression for images on the web. Using WebP, webmasters and web developers can create smaller, richer images that make the web fasterWed, 07 Mar 2018 23:18:38 -05002018-03-07T23:18:38-05:0019941https://dejanstojanovic.net/powershell/2018/march/converting-existing-website-images-to-google-webp-using-powershell/PowerShellConverting existing website images to Google WebP using PowerShellWebP is an image format introduced by Google in 2010. It uses specific technique to compress image and reduce size significantly while not changing the image quality on the larger scaleTue, 06 Mar 2018 11:20:51 -05002018-03-06T11:20:51-05:0019940https://dejanstojanovic.net/powershell/2018/march/optimize-jpg-images-for-internet-using-jpegtran-and-powershell/PowerShellOptimize JPG images for internet using jpegtran and PowerShellRecently I wrote an article about optimizing PNG images for intenrent using pngcrush and PowerShell. I actually used this method to optimize all PNG images on my websiteTue, 06 Mar 2018 03:27:34 -05002018-03-06T03:27:34-05:0019939https://dejanstojanovic.net/powershell/2018/march/optimize-png-images-for-internet-using-pngcrush-and-powershell/PowerShellOptimize PNG images for internet using pngcrush and PowerShellImagine a case where you have an existing website which is running for the past few years. You decided to run a Google PageSpeed insights on couple of pages and you realized that your PNG images on the pages are not optimized for InternetMon, 05 Mar 2018 11:40:57 -05002018-03-05T11:40:57-05:0019938https://dejanstojanovic.net/powershell/2018/march/minify-css-and-javascript-files-with-powershell-script/PowerShellMinify CSS and JavaScript files with PowerShell scriptMinification of Cascade Style Sheet (CSS) and Java Script (JS) should be on a TODO list for every web application.  The minification of CSS and JS can be easily one on the runtime with ASP.NET bundling which is build in in ASP.NET framework, but in case of distributing your resource files over CDN you cannot use the runtime minification. You physical files need to be minifiedSun, 04 Mar 2018 04:49:57 -05002018-03-04T04:49:57-05:0019935https://dejanstojanovic.net/aspnet/2018/march/switch-from-http-to-https-in-existing-aspnet-web-application/.NETSwitch from HTTP to HTTPS in existing ASP.NET web applicationStarting from few years ago, Google enforces secured over unsecured website traffic. However it is an ongoing process since both publishers and advertisers need to implement HTTPS in order to avoid mixed contnet exception in a browser and preventing ads to load on a website. Sat, 03 Mar 2018 03:35:47 -05002018-03-03T03:35:47-05:0019933https://dejanstojanovic.net/umbraco-cms/2018/march/minify-html-output-of-your-pages/Umbraco CMSMinify HTML output of your pagesMinification of resource can speed up your page load and decrease network traffic making you pages load faster, especially on a poor Internet connections. Keep in mind that not all of your website visitors have high speed Internet connectionFri, 02 Mar 2018 22:47:02 -05002018-03-02T22:47:02-05:0019925https://dejanstojanovic.net/aspnet/2018/february/export-dataset-and-datatable-to-excel-with-c/.NETExport DataSet and DataTable to Excel with C#Some time ago I wrote an article on how to export data to Excel from C# code. Essentially it exports data to file which can be opened in Excel but it does not produce the actual Microsoft Office Excel document. I recently wrote an article on Working with Excel files in .NET without using COM in C#, so I decided to use this approach to create extension methods for DataTable and DataSet classesWed, 28 Feb 2018 23:11:57 -05002018-02-28T23:11:57-05:0019923https://dejanstojanovic.net/aspnet/2018/february/export-datatable-to-html-in-c/.NETExport DataTable to HTML in C#When I searched for exporting s to HTML table in C# I found a lot of articles and code snippets which are basically doing string concatenation or String.Format on the hard-coded HTML String to generate HTML string of the table. To me this approach is a bit like a workaround and I was never a fan of hard-coding values. In addition, code with a lot of hard-coded value end up as hardly maintainable codeWed, 28 Feb 2018 04:34:05 -05002018-02-28T04:34:05-05:0019922https://dejanstojanovic.net/aspnet/2018/february/working-with-excel-files-in-net-without-using-com/.NETWorking with Excel files in .NET without using COMExcel is a common format for storing tabular data. It is a powerful tool from Microsoft Office package. Since it is often format for string data, it is often required to work with this data from the third party applicationsTue, 27 Feb 2018 03:22:47 -05002018-02-27T03:22:47-05:0019918https://dejanstojanovic.net/aspnet/2018/february/simplest-way-to-store-lists-and-dictionaries-in-config-files/.NETSimplest way to store lists and dictionaries in config filesConfiguration files are a useful place too keep any related configuration settings. It provides easy to use configuration fetching which you can invoke from any part of the application. However it does not support many stuff out of the box, but on the other hand it is pretty flexible and expendable. One of the things that are not there built in is support for lists. Sun, 25 Feb 2018 04:12:13 -05002018-02-25T04:12:13-05:0019917https://dejanstojanovic.net/aspnet/2018/february/send-data-to-azure-log-analytics-from-c-code/.NETSend data to Azure Log Analytics from C# codeAzure as a part of  Microsoft Operations Management Suite provides data collection and insight services inside Azure cloud platform. It allows you to: Sun, 25 Feb 2018 02:06:12 -05002018-02-25T02:06:12-05:0019916https://dejanstojanovic.net/aspnet/2018/february/multiple-file-upload-with-aspnet-webapi/.NETMultiple file upload with ASP.NET WebApiTaking out business logic from the application allows different clients running on a different platform to use same logic. REST API is a great way to decuple business logic and make it available to different clients on a different platforms.  To upload files using WebApi we first need to define an action in a WebApi controller to handle files posted to the endpoint. Sat, 24 Feb 2018 09:16:09 -05002018-02-24T09:16:09-05:0019913https://dejanstojanovic.net/powershell/2018/february/merge-folders-with-windows-powershell-script/PowerShellMerge folders with Windows PowerShell scriptWhen deploying application to specific location it is often required to deploy only few files and not the whole deployment package. For example, if you changed only single static image file in your ASP.NET WebApplication, there is no reason to overwrite bin folder content and cause WebApplication on IIS to restartThu, 22 Feb 2018 05:10:06 -05002018-02-22T05:10:06-05:0019912https://dejanstojanovic.net/aspnet/2018/february/installing-same-windows-service-under-a-different-name/.NETInstalling same Windows service under a different nameMicrosoft .NET framework comes with a really good support for Windows services. Regarding the project itself, Visual Studio IDE comes with build in project template for Windows service. .NET framework itself comes with a built in tool installutil for deploying the Windows Service projectSun, 18 Feb 2018 23:54:23 -05002018-02-18T23:54:23-05:0019911https://dejanstojanovic.net/powershell/2018/february/sending-email-with-gmail-account-using-powershell-script/PowerShellSending email with Gmail account using PowerShell scriptSending email after and even before a long running PowerShell script is a logical thing to do to notify users which are responsible for taking actions for the specific operation.  PowerShell starting from version 3.0 has build in cmdlet Send-MailMessage for sending emails. Sun, 18 Feb 2018 01:34:38 -05002018-02-18T01:34:38-05:0019904https://dejanstojanovic.net/powershell/2018/february/use-powershell-to-install-ssl-certificate-on-iis/PowerShellUse PowerShell to install SSL certificate on IISSince Google announced HTTPS as ranking signal most of the websites now days are switching to secured communication via SSL certificates. Even I switched my website to HTTPS secured connection to follow up with this new trend. Using certificate on the website is related to domain binding, but even before we setup the domain binding for the website, we need to import the certificate to IISThu, 15 Feb 2018 14:39:30 -05002018-02-15T14:39:30-05:0019901https://dejanstojanovic.net/powershell/2018/february/get-net-framework-version-installed-on-windows-using-powershell/PowerShellGet .NET Framework version installed on Windows using PowerShellFinding out installed .NET Framework version on the host Windows OS is not an everyday job, but when it comes to deployments of the .NET application it is needed to check if the host supports targeting .NET Framework version. Starting from .NET Framework 4.5, Microsoft is storing .NET Framework version as a key in registry HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\Release Thu, 08 Feb 2018 11:17:07 -05002018-02-08T11:17:07-05:0019898https://dejanstojanovic.net/aspnet/2018/february/reasons-for-aspnet-application-restarts-on-iis-server/.NETReasons for ASP.NET application restarts on IIS serverIf you were experiencing you ASP.NET Web Application to restart, there are few possible reasons for that, but before we jump to resons why ASP.NET web application hosted on IIS gets restarted let's first look at the relation between IIS and ASP.NET Wed, 07 Feb 2018 11:32:40 -05002018-02-07T11:32:40-05:0019893https://dejanstojanovic.net/aspnet/2018/february/exporting-ssl-certificate-to-pfx-format-for-using-on-iis-or-azure/.NETExporting SSL certificate to PFX format for using on IIS or AzureHether your website requires SSL secured connection through HTTPS or not, it is even recommended by Google to use SSL for your website. Starting from 2005 Google page ranking takes into consideration whether your page has SSL certificate installed and serer content thorough HTTPS. If you are hosting your website on IIS, you have some built in tols in Internet Information Service (IIS) manager, for SSL certificate operations but they are pretty limited and most of the time confusing to use.  Sun, 04 Feb 2018 09:42:18 -05002018-02-04T09:42:18-05:0019891https://dejanstojanovic.net/powershell/2018/february/managing-windows-scheduled-tasks-with-windows-powershell/PowerShellManaging Windows Scheduled Tasks with Windows PowerShellMicrosoft Windows Task Scheduler component is a standard part of Microsoft Windows operating system since Windows98. It allows schedulex execution of programs or scripts at specific pre-defined time or recurrent time interval. Repetitive creating and updating Windows Scheduled Tasks manually using Windows built in manager can be annoyingFri, 02 Feb 2018 04:27:48 -05002018-02-02T04:27:48-05:0019887https://dejanstojanovic.net/powershell/2018/january/complex-parameters-in-windows-powershell-scripting/PowerShellComplex parameters in Windows PowerShell scriptingLike in any other language, in PowerShell we also want to reuse our code and execute same set of operations with different parameters. PowerShell has great support for parameters which can be used in PowerShell script invocation.If you want your script to accept parameters you need to declare them in the script fileSun, 28 Jan 2018 23:13:03 -05002018-01-28T23:13:03-05:0019863https://dejanstojanovic.net/powershell/2018/january/setting-aspnet-application-on-iis-always-running-with-powershell/PowerShellSetting ASP.NET application on IIS always running with PowerShellWhen creating new website with new application pool, bu default IIS sets your application pool in a way to save resources when inactive. This is because it does not want to run your website all the time if is there is no activity on it and keep using resources on the host for idle worker processes (w3wp.exe). This is the reason you might experience slow response when opening your website URL from time to time especially if your website has low traffic. Wed, 24 Jan 2018 07:14:07 -05002018-01-24T07:14:07-05:0019862https://dejanstojanovic.net/aspnet/2018/january/concatenate-list-of-strings-in-c-using-linq/.NETConcatenate list of strings in C# using LINQMore often you will need a list of strings from a single string with a Split method, not so often you need to get a single string from an IEnumerable of strings, but still those requirements exist form time to time. This does not look like a complex tasks, but still there are several ways to achieve this. Mon, 22 Jan 2018 23:34:43 -05002018-01-22T23:34:43-05:0019861https://dejanstojanovic.net/aspnet/2018/january/get-number-of-messages-in-msmq-with-c/.NETGet number of messages in MSMQ with C#MSMQ (Microsoft Message Queuing) is a built in Windows component. It is not so popular now days as there are more efficient and robust solutions available. However, it still has it's place in application architecture as a simple queueing system, plus as I mentioned, it comes out of the box with Windows operating system as a Windows component.This means it is still widely used Windows based applications mostly for internal notifications and services between components of the solutionSun, 21 Jan 2018 22:44:52 -05002018-01-21T22:44:52-05:0019860https://dejanstojanovic.net/powershell/2018/january/automated-clean-up-and-archive-of-log-files-with-powershell-5/PowerShellAutomated clean up and archive of log files with PowerShell 5Depending on the application architecture, your Windows virtual machine might have one or more applications or components of a single solution. Those might be WebApi services, Web Applications or Windows applications. Any of these components may generate logs which are important for diagnostics and tracking down eventsFri, 19 Jan 2018 02:35:21 -05002018-01-19T02:35:21-05:0019857https://dejanstojanovic.net/powershell/2018/january/clean-up-iis-log-files-from-web-server-using-powershell/PowerShellClean up IIS log files from web server using PowerShellMicrosoft IIS Server is by default logging every request that reaches it. This can be pretty useful for tracking down the issue which my occur over time, but it is also pilling up log files on server's disk which eventually can cause low disk space. You an always clean up these files manually, but wouldn't it be nice if server does that for you? Wed, 17 Jan 2018 07:27:19 -05002018-01-17T07:27:19-05:0019853https://dejanstojanovic.net/powershell/2018/january/setting-up-iis-aspnet-webapplication-using-powershell/PowerShellSetting up IIS ASP.NET WebApplication using PowerShellPowerShell is the best option for automation on Windows platform. Regardless of which platform and how you organize Continous Deployment, you will always need to introduce certain level of customization during the deployment process. Scripting with PowerShell can play main role with these kind of customizationsWed, 17 Jan 2018 05:03:05 -05002018-01-17T05:03:05-05:0019852https://dejanstojanovic.net/powershell/2018/january/setting-permissions-for-aspnet-application-on-iis-with-powershell/PowerShellSetting permissions for ASP.NET application on IIS with PowerShellVery often you need to setup ASP.NET Web application on IIS server, you need to setup file and folder permission for your application on order to access content of specific folder. This can be easily done through Windows Explorer Properties window in the Security tab. Sun, 14 Jan 2018 23:57:36 -05002018-01-14T23:57:36-05:0019851https://dejanstojanovic.net/aspnet/2018/january/javascript-base64-image-to-bitmap-in-c/.NETJavaScript base64 image to Bitmap in C#Base64 serialized images are useful in many cases for serving images on page. It is also a format of image that JavaScript can generate on the fly. HTML canvas object has native support for base64 and it can be easily serialized to base64 string from JavaScript code by invoking toDataURL method of the canvas element. Sun, 14 Jan 2018 01:30:11 -05002018-01-14T01:30:11-05:0019849https://dejanstojanovic.net/aspnet/2018/january/separate-configuration-files-per-build-config-in-visual-studio/.NETSeparate configuration files per build config in Visual Studio IDEIt is an often case that application configuration is different for each environment. Most often this is the case for database connection string where developer has connection string to dev environment database or it's local database and quality assurance (qa) and production have different connection strings wile the rest of the configSat, 13 Jan 2018 06:06:04 -05002018-01-13T06:06:04-05:0019847https://dejanstojanovic.net/aspnet/2018/january/manage-iis-website-from-aspnet-code/.NETManage IIS website from ASP.NET codeMicrosoft made IIS management from the ASP.NET code itself much easer and accessible right out of the box by introducing Microsoft.Web.Administration library.  Simply by adding the reference in your project to Microsoft.Web.Administration library you are getting options to manage websites hosted on the IIS where application is running. One of the requirements beside referencing Microsoft.Web.Administration library is setting your Application Pool to run under LocalSystem account. Thu, 11 Jan 2018 11:48:35 -05002018-01-11T11:48:35-05:0019842https://dejanstojanovic.net/aspnet/2017/december/using-gzip-compression-for-large-text-values-in-redis/.NETUsing GZip compression for large text values in RedisUsing REDIS for caching values for increasing application performance can be quite beneficial and can increase performance and scalability of your application. Although REDIS allows quite large text files, up to 512MB which is something you most likely will not reach if you are storing for example JOSN data, there will be a significant network transfer over the wire for putting and pulling this value in and outSun, 24 Dec 2017 07:25:59 -05002017-12-24T07:25:59-05:0019840https://dejanstojanovic.net/aspnet/2017/october/qr-code-mvc-html-helper/.NETQR code MVC html helperThis article is based on one of my previous topic Advanced Base64 image extension in ASP.NET MVC. It uses the same concept to display image on the page and to cache it, but it involves QR code bitmap generation which is basically a NuGet package use. Basically, QR code is generated using NuGet package QRCoder https://www.nuget.org/packages/QRCoder/ and result Bitmap is serialized to base64 string and cached so we do not regenerate same QR bitmap over and over on every request which may lead to server overload. Mon, 09 Oct 2017 01:03:52 -04002017-10-09T01:03:52-04:0019838https://dejanstojanovic.net/aspnet/2017/september/clean-stop-of-windows-service-in-net/.NETClean stop of Windows Service in .NETThe common reason I wrote Windows Services applications for are usually workers. For example, you need to read messages from the queue and process themWed, 20 Sep 2017 12:49:17 -04002017-09-20T12:49:17-04:0019837https://dejanstojanovic.net/aspnet/2017/september/posting-json-to-webapi-without-reference-to-a-model-in-c/.NETPosting JSON to WebApi without reference to a model in C#Web API and in general REST services are becoming more and more often used layer of the applications. It relies on the HTTP, it is lighter than the SOAP and more natural to JavaScript, therefore easy to use both from the client and serer sideTue, 12 Sep 2017 11:14:57 -04002017-09-12T11:14:57-04:0019832https://dejanstojanovic.net/aspnet/2017/may/advanced-base64-image-extension-in-aspnet-mvc/.NETAdvanced Base64 image extension in ASP.NET MVCSerializing images to base64 string is well known technique to reduce requests per page. Each image on the page produces a separate request while page is loadingSat, 13 May 2017 04:58:34 -04002017-05-13T04:58:34-04:0019830https://dejanstojanovic.net/aspnet/2017/may/aspnet-core-web-api-versioning/.NETASP.NET Core Web API versioningWhen it comes to WebAPI many project overlook the versioning aspect. The whole concept of WebAPI is to serve multiple types of clients which can be based on different platforms, run on different devices etcFri, 12 May 2017 12:39:52 -04002017-05-12T12:39:52-04:0019828https://dejanstojanovic.net/javascript/2017/may/non-blocking-css-load-on-the-page/JavaScriptNon blocking CSS load on the pageLike JavaScript, CSS files are also loaded on the page by default in a blocking manner. Luckily for us, for JavaScript we can use either async or defer attributes on the script tag itself to change the behavior of JavaScript external file loadingTue, 09 May 2017 12:19:50 -04002017-05-09T12:19:50-04:0019824https://dejanstojanovic.net/aspnet/2017/april/inline-javascript-and-css-tags-with-aspnet-mvc/.NETInline JavaScript and CSS tags with ASP.NET MVCWith ASP.NET MVC Microsoft introduced bundling of JavaScript and CSS resources. These bundles work pretty well but to me it always looks not so natural to define bundles in BundleConfig.css and I had problems if I want  to edit CSS or JavaScript during runtime because they are cachedWed, 26 Apr 2017 13:29:21 -04002017-04-26T13:29:21-04:0019823https://dejanstojanovic.net/aspnet/2017/april/google-service-account-authentication-in-net/.NETGoogle Service Account authentication in .NETIn case you are a .NET developer and you are using Google Cloud platform, eventually your apps or services will have to interact with Google Cloud (GCE) services. Good thing is that complete GCE is exposed through REST API. Whole authentication is done through OAuth 2.0, but the authentication of website applications and your services which might be running in background on your server is not the sameMon, 24 Apr 2017 01:41:27 -04002017-04-24T01:41:27-04:0019819https://dejanstojanovic.net/javascript/2017/march/serialize-html-form-to-json-without-using-jquery/JavaScriptSerialize html form to JSON without using JQueryjQuery makes things a lot easir when working with DOM. So many thing there out of the b and you do not need to worry about browsr compatibility. Browser compatibility used to be a big deal few years back, but not it all comes to almost one engine which is WebKit. Thu, 16 Mar 2017 03:13:47 -04002017-03-16T03:13:47-04:0019816https://dejanstojanovic.net/aspnet/2017/march/clean-up-iis-log-files-from-you-web-server/.NETClean up IIS log files from you web serverMicrosoft IIS Server is by default logging every request that reaches it. This can be pretty useful for tracking down the issue which my occur over time, but it is also pilling up log files on server's disk which eventually can cause low disk space. You an always clean up these files manually, but wouldn't it be nice if server does that for you? Wed, 15 Mar 2017 11:28:11 -04002017-03-15T11:28:11-04:0019813https://dejanstojanovic.net/aspnet/2017/january/why-is-jsonrequestbehavior-needed/.NETWhy is JsonRequestBehavior needed?You probably run to this exception when you tried to fetch JSON data over HTTP GET request. Now, first this is easy to bypass by simply adding JsonRequestBehavior.AllowGet option to method which is retutning JSON data for GET request in a controller file. Wed, 18 Jan 2017 05:48:37 -05002017-01-18T05:48:37-05:0019809https://dejanstojanovic.net/aspnet/2016/december/dictionary-to-object-in-c/.NETDictionary to object in C#Dictionaries are very useful as data holders for any type of the code in C#. You can easily manipulate data stored on collections, but there are disadvantages like posting data to REST JSON serviceFri, 23 Dec 2016 01:14:55 -05002016-12-23T01:14:55-05:0019808https://dejanstojanovic.net/aspnet/2016/december/office365-authentication/.NETSimple Office365 authenticationWith so many online and cloud based services, adding one more additional account for your application adds additional complexity level for your users since they will have to manage one more account and remember one more password. Microsft ASP.NET comes with pretty nice built in provides for social networks, but for office usage social networks are not so convenient to be used. Sat, 17 Dec 2016 22:31:25 -05002016-12-17T22:31:25-05:0019806https://dejanstojanovic.net/sql/2016/april/create-xmlhtml-with-t-sql/SQL/T-SQLCreate XML/HTML with T-SQLSending email from SQL is not a difficult to achieve, but generating rich HTML content might be. SQL Server itself is not built as a text processor, first approach would be to build HTML by simple concatenating the string elements. This approach will work, but over time it will become more and more difficult to maintain especially if you need to add layout elements over time. Thu, 28 Apr 2016 03:32:52 -04002016-04-28T03:32:52-04:0019801https://dejanstojanovic.net/aspnet/2016/march/msmq-recovery-with-net/.NETMSMQ recovery with .NETMSMQ is a bit old stuff and there are bunch of other products out here which perform better in most of the scenarios, but MSMQ is still used in a lot of solutions and Microsoft still did not announce support ending for MSMQ so it will be for sure some more time around.One of the stuff that is missing as out of the box feature in MSMQ is recovery. In scenarios you get the message from the queue and try to process, and process fails, in some of the cases you might want to try to process the message againSun, 27 Mar 2016 09:45:25 -04002016-03-27T09:45:25-04:0019797https://dejanstojanovic.net/aspnet/2016/february/serialize-datatable-to-json-with-just-few-lines-of-code/.NETSerialize DataTable to JSON with just few lines of codeAlthough JSON is widely used as a format for sharing the data, there are still existing solutions or modules that still rely on ADO and DataTables. Even today it very common to see some piece of code which deals with DataTable or DataReader for the performance reasons. In the end if any of the ADO objects needs to be exposed as a JSON string you have to write your own serialization code. Tue, 02 Feb 2016 09:01:28 -05002016-02-02T09:01:28-05:0019795https://dejanstojanovic.net/javascript/2016/january/copy-text-value-to-clipboard-using-jquery/JavaScriptCopy text value to clipboard using jQueryI recently needed to copy some value from the web UI to clients clipboard. Since this is not something you often need to use, I googled a little bit and found that this is easy to do with document.execCommandSun, 17 Jan 2016 07:47:24 -05002016-01-17T07:47:24-05:0019794https://dejanstojanovic.net/aspnet/2016/january/simplified-fileattributes-usage-with-extension-methods/.NETSimplified FileAttributes usage with extension methodsIn case you are working on a small project where you just store some files and access them, you do not really need a database to achieve accessibility and additional info to files or folders. File-system itself is providing some stuff which can be useful for thisWed, 13 Jan 2016 00:02:51 -05002016-01-13T00:02:51-05:0019793https://dejanstojanovic.net/javascript/2016/january/resize-image-on-the-client-side-with-jquery/JavaScriptResize image on the client side with JQueryImage resizing is considered as a server side operation as JavaScript and HTML were not so sophisticated and HTML5 support was not widely adopted for quite some time. even now, some features are not equally supported by all major browsers. Anyhow, HTML5 is here to stay and over time we will get more and more features supported by all browsers. Mon, 11 Jan 2016 06:38:38 -05002016-01-11T06:38:38-05:0019787https://dejanstojanovic.net/aspnet/2016/january/sqlbulkcopy-with-model-classes-in-c/.NETSqlBulkCopy with model classes in C#So far (based on my experience) the fastest way to insert big number of records from application to database is to use SqlBulkCopy. The downsize of this is that SqlBulkCopy uses DataTable instace as an input parameter which is not so convenient when dealing with models which are strongly typed and a lot more easy to use than iterating through the DataTableSun, 03 Jan 2016 03:30:19 -05002016-01-03T03:30:19-05:0019781https://dejanstojanovic.net/javascript/2015/december/googlemaps-route-jquery-plugin/JavaScriptGoogleMaps route jQuery pluginTo make it easier for your customers to find your store location it is really important to show them where you are, but what can make even better impact is to show them where you are based on their current location and to guide them to you. GoogleMaps are a powerful tool for that, but you have to spend some time (more or less) to find code snippets and understand how to invoke their API, add the proper references, handle exceptions which might occur during the communication between your website and GoogleMaps API etc. Sat, 19 Dec 2015 09:27:51 -05002015-12-19T09:27:51-05:0017777https://dejanstojanovic.net/aspnet/2015/november/short-url-implementation-with-webapi/.NETShort URL implementation with WebAPIToday there are multiple URL shortening solution available online for free. However, there is always need to have some existing funtionalities in the house for various reasonsMon, 30 Nov 2015 22:54:31 -05002015-11-30T22:54:31-05:0016776https://dejanstojanovic.net/sql/2015/november/ip-address-to-octets-split-in-tsql/SQL/T-SQLIP address to octets split in TSQLIn case you need to handle IP addresses in SQL, they are not much useful as string values. To do anything with them rather then just storing and retrieving (checking the ranges for example) you need to split IP address to segments (octets). The following is modified method I run into online. Tue, 24 Nov 2015 21:29:08 -05002015-11-24T21:29:08-05:0016774https://dejanstojanovic.net/aspnet/2015/november/debugging-windows-service-application-with-console-in-c/.NETDebugging Windows Service application with console in C#Developing Windows Service might a a real headache since you do not have any visual part to see the output. Even if you want to rely on Visual Studio debugger you need to install the service, stop it (if already running), deploy, start the service from Windows MMC and finally hook up Visual Studio to the running service processThu, 19 Nov 2015 06:18:01 -05002015-11-19T06:18:01-05:0016773https://dejanstojanovic.net/aspnet/2015/november/non-blocking-writing-to-console-in-c/.NETNon blocking writing to console in C#The fast and most commonly used method to debug code is for sure using console applications. Since main operations are reading input and writing output, it does not take much to set it up and start debugging your code. One more reason for using console application is to test the performanceWed, 18 Nov 2015 22:32:21 -05002015-11-18T22:32:21-05:0014763https://dejanstojanovic.net/aspnet/2015/october/ip-address-filtering-from-c-code-in-aspnet-mvc-and-web-api/.NETIP address filtering from C# code in ASP.NET MVC and Web ApiLast year I wrote an article about IP address filtering on MVC and WebApi Restrict Access to an MVC Action or Controller based on IP address. Over time the requirements for IP filtering in several web based application increased, so I had t work on this class to make it more extendible and reusable in different scenariosFri, 30 Oct 2015 10:16:03 -04002015-10-30T10:16:03-04:0014756https://dejanstojanovic.net/aspnet/2015/october/net-managed-scheduled-task-runner/.NET.NET managed scheduled task runnerSometime ago I wrote an article about Windows Scheduled Task vs Windows Service where I compared and listed benefits and drawbacks of using scheduled tasks in Windows and Windows Services for executing certain operation which repeats in some time span. However idea of executing tasks in a single Windows Service is very useful if you need to execute task in a short time span plus you have a full control including logging and other fine grained customization in case you write the task in your codeThu, 22 Oct 2015 02:20:02 -04002015-10-22T02:20:02-04:0012757https://dejanstojanovic.net/javascript/2015/october/embedding-images-in-css-as-base64-strings/JavaScriptReduce the number of request from the page by using base64 in CSSOne of the major things that affects your page performance is the number of requests made from your page. Any external resource included on the page page makes your page loads slower. Most commonly these are imagesWed, 14 Oct 2015 09:14:03 -04002015-10-14T09:14:03-04:0012752https://dejanstojanovic.net/aspnet/2015/october/msmq-json-message-formatter/.NETMSMQ JSON message formatterStoring objects in the message queue (MSMQ) is based on the serialization of the object instance using some of the serializes, basically any class the implements IMessageFormatter. Most commonly used ones are BinaryMessageFormatter and XmlMessageFormatter. I prefer XmlMessageFormatter over BinaryMessageFormatter, mostly because messages are stored in a readable format inside the queue, so in case something goes wrong you can direly check the content of the message using built Computer Management MMC (Microsoft management console) in the. Tue, 06 Oct 2015 01:46:29 -04002015-10-06T01:46:29-04:0010751https://dejanstojanovic.net/aspnet/2015/september/parallel-infinite-loop-in-c/.NETParallel infinite loop in C#In .NET framework 4.5 Task Parallel Library of TPL is introduced. It is the same thing as Threading but in additional layer of abstractionMon, 28 Sep 2015 03:25:54 -04002015-09-28T03:25:54-04:0010750https://dejanstojanovic.net/aspnet/2015/september/easy-collection-comparing-in-c/.NETEasy collection comparing in C#Collections are part of pretty much any application and they are convenient to store any type of data. Introducing LINQ in .NET things got a lot easier as your code does not need to be full with loops for performing simple operations on collections of any typeFri, 25 Sep 2015 09:08:22 -04002015-09-25T09:08:22-04:0010749https://dejanstojanovic.net/aspnet/2015/september/multiple-console-output-in-c/.NETMultiple console output in C#Console applications are the simplest one and very convenient when you need to quickly test some functionality. Some time the functionality that you test with console application may take time and since it is test usually it happens that it crashesFri, 25 Sep 2015 07:41:33 -04002015-09-25T07:41:33-04:0010747https://dejanstojanovic.net/javascript/2015/september/parsing-date-from-facebook-opengraph-api-response-with-javasscript/JavaScriptParse date of Facebook OpenGraph API response with JavasScriptRecently I had an issue while working on an update for my Facebook Album Browser plugin with dates returned from Facebook OpenGraph API. The dates are returned in the following form 2011-06-13T23:31:19+0000 and luckily for me, converting this string to an actual Date object in JavaScript worked pretty well for most of the browsers, but some of them like Safari on iPad did not know to convert this string to a Date object and because of that I was getting default JavaScript date 1970-01-01 00:00:00 UTC+00. After some time spent googling and checking regular expressions, I did not find a suitable solution for this. Sun, 06 Sep 2015 11:13:17 -04002015-09-06T11:13:17-04:0010744https://dejanstojanovic.net/aspnet/2015/august/json-data-validation-in-c/.NETJSON data validation in C#JSON is slowly but certainly taking over the throne of XML. It is much lighter, a lot easier to deserialize, but still there are some features that XML is better inSun, 30 Aug 2015 10:37:50 -04002015-08-30T10:37:50-04:0010736https://dejanstojanovic.net/javascript/2015/july/delayed-execution-in-javascript/JavaScriptDelayed execution in JavaScriptNot very often, but from time to time you need to slow down your code. Most of the time the reason for that is that you need to test some long execution, mostly external source callThu, 30 Jul 2015 12:37:31 -04002015-07-30T12:37:31-04:0010734https://dejanstojanovic.net/sql/2015/july/getting-first-and-last-second-of-the-current-year-month-and-day/SQL/T-SQLGetting first and last second of the current year, month and dayProbably the most common error developers make in queries is dealing with date ranges and most of the time it is because of missing the minimum and maximum time of the specific date. Month Mon, 20 Jul 2015 04:22:32 -04002015-07-20T04:22:32-04:0010731https://dejanstojanovic.net/aspnet/2015/july/changing-service-reference-configuration-in-the-runtine/.NETChanging service reference configuration in the runtineUsing web services in C# and in general in .NET based applications is really easy. All you need is a service URL and Visual Studio will generate both proxy classes for service communication and configuration for web service endpoints and bindingsWed, 08 Jul 2015 12:00:42 -04002015-07-08T12:00:42-04:0010730https://dejanstojanovic.net/aspnet/2015/july/hide-iis-server-info-in-a-resposne/.NETHide IIS server info in a resposneLast year I wrote an article about ASP.NET web application security check list. Apparently there are always more things to add to improve your web application securityFri, 03 Jul 2015 01:36:20 -04002015-07-03T01:36:20-04:0010726https://dejanstojanovic.net/aspnet/2015/june/managing-keys-for-shared-collections-in-net/.NETManaging keys for shared collections in .NETDealing with shared collection in application is always a bit tricky. You have to take care of concurrent access if you are accessing from multiple threads. One more thing which does not look so important as it is not difficult to implement is managing keys for addressing valuesWed, 17 Jun 2015 08:36:19 -04002015-06-17T08:36:19-04:0010725https://dejanstojanovic.net/aspnet/2015/june/auto-realod-application-config-in-net/.NETAuto reload application config in .NETIn .NET working with configuration is really easy and there are bunch of .NET classes that rely on config values so you do not have to specify values in their constructors. For me it a common practice to instantiate database connections of WCF client by only creating an instance with parameterless constructor while keeping values in config fileFri, 12 Jun 2015 07:18:16 -04002015-06-12T07:18:16-04:0010723https://dejanstojanovic.net/javascript/2015/june/disabling-browser-ui-effects-from-css/JavaScriptDisabling browser UI effects from CSSNew version of browsers are bringing a lots of useful features, but among them there are some features that can actually ruin your UI concept. The following are just some of the most common ones and instructions how to disable them. Disable textarea rezise Tue, 02 Jun 2015 21:31:29 -04002015-06-02T21:31:29-04:0010721https://dejanstojanovic.net/aspnet/2015/june/easy-and-simple-way-to-bind-ado-object-to-poco-object/.NETEasy and simple way to bind ADO object to POCO objectThis article is base don the article I wrote in September last year. Basically I wrote this piece of code because I needed something really lite for one way bindingTue, 02 Jun 2015 02:04:02 -04002015-06-02T02:04:02-04:0010717https://dejanstojanovic.net/aspnet/2015/may/powerconsole-extension-to-systemconsole/.NETPowerConsole extension to System.ConsoleMost of developers, at least all the ones I know mostly use Console to test their code as it is the quickest way to do it. Despite unit tests, console is a fastest way to test your code where you can easily output the results. However if you have a lot of text in output you can get lost in resultsSun, 24 May 2015 22:23:34 -04002015-05-24T22:23:34-04:0010714https://dejanstojanovic.net/javascript/2015/may/working-with-googlemaps-in-jquery-style/JavaScriptWorking with GoogleMaps in jQuery styleI've used GoogleMaps on several web projects and it seemed to me that I'm repeating a lot of code used in the previous projects which lead me to write a common Javascript library to help me easily reuse the code by only copying the JavaScript library to a project or referencing it from CDN. I could not think of a better way to build this library than to use jQuery and build a pligin for this. Sun, 17 May 2015 20:39:05 -04002015-05-17T20:39:05-04:0010711https://dejanstojanovic.net/aspnet/2015/may/reading-config-value-to-a-proper-data-type/.NETReading config value to a proper data typeReading from application config is pretty easy in .NET. You literally need one line to fetch the valueWed, 13 May 2015 02:14:53 -04002015-05-13T02:14:53-04:009711https://dejanstojanovic.net/umbraco-cms/2015/april/generate-sitemapxml-on-the-fly-in-umbraco-cms/Umbraco CMSGenerate sitemap.xml on the fly in Umbraco CMSSitemap.xml is important component of SEO which is responsible for indexing your website. Search engine robots are generating indexes of your website based on this file. Since content in Umbraco website is dynamic, it makes not so much sence to have static sitemap.xml file for indexing your contentSat, 18 Apr 2015 08:44:10 -04002015-04-18T08:44:10-04:009709https://dejanstojanovic.net/aspnet/2015/april/fast-image-search-in-net-using-c/.NETFast image search in .NET using C#Searching files on the file system is pretty easy using System.IO namespace classes. The problem is if you need to youery file system with some things which are related to a file, but not related to file system itselfThu, 16 Apr 2015 02:31:54 -04002015-04-16T02:31:54-04:009708https://dejanstojanovic.net/aspnet/2015/april/benefits-of-binary-serialization-in-c/.NETBenefits of binary serialization in C#By default object instances in .NET are never "trully" clonned. Instead .NET is doing shallow copy of instances which means if you have one variable which is object instance and you assign that variable to other variable, both of them will point the same instance of that objectTue, 14 Apr 2015 20:55:31 -04002015-04-14T20:55:31-04:009706https://dejanstojanovic.net/aspnet/2015/april/scraping-website-content-using-htmlagilitypack/.NETScraping website content using HtmlAgilityPackHTML is a markup language same as XML, but still there are differences which make dealing with them a bit different. Basically HTML is a strict structure in terms of node sets and attribute sets, but in general more documents online are not exactly following the proper structure since browsers usually manage to deal with rendering out the document in UITue, 14 Apr 2015 04:22:09 -04002015-04-14T04:22:09-04:009705https://dejanstojanovic.net/sql/2015/april/dealing-with-duplicate-rows-in-sql-server/SQL/T-SQLDealing with duplicate rows in SQL ServerIn case your data in tables needs to have unique constraint based on more than one value in the row, the proper solution for that would be a composite key. Mon, 13 Apr 2015 10:24:00 -04002015-04-13T10:24:00-04:009700https://dejanstojanovic.net/aspnet/2015/april/microsoft-iis-and-aspnet-mvc-caching-techniques/.NETMicrosoft IIS and ASP.NET MVC caching techniquesOf course, the best way to make you web application work fluent is to write the code properly and design the architecture of application to meet requirements and certain load depending of the type of application. But even though architecture is good, you can always improve performance by reducing processing in application code itselfThu, 09 Apr 2015 02:42:41 -04002015-04-09T02:42:41-04:009697https://dejanstojanovic.net/aspnet/2015/april/block-referrer-spam-request-on-aspnet-application/.NETBlock referrer spam request on ASP.NET applicationRecently I was checking my Google Analytics for this website I spotted some referrer urls that were completely unknown to me. When I tried to visit the url of the referrers I got a lot of commercial and pop-ups after few redirects. It looked really suspicious, so I tried to find a little bit more about these. Thu, 02 Apr 2015 04:59:02 -04002015-04-02T04:59:02-04:009694https://dejanstojanovic.net/javascript/2015/march/recognize-links-in-text-content-with-jquery/JavaScriptRecognize links in text content with jQueryVery often when you are dealing with content from 3rd party like tweets from Twitter of Facebook posts and comments you might end up with some URL inside the content. On both Twitter or Facebook or any other social network, links inside text comments are replaces with anchor tags to those URLs. In order to keep the same user experience and make it more useful o your side where you are serving the content from the other party it is recommended that you do the same. Mon, 30 Mar 2015 09:22:49 -04002015-03-30T09:22:49-04:009689https://dejanstojanovic.net/aspnet/2015/march/enabling-cors-only-for-specific-domains-in-aspnet/.NETEnabling CORS only for specific domains in ASP.NETCross-origin resource sharing (CORS) means that page from other domain can make request to some resource which is on other domain. For example, if you try to invoke some WEB API method which is running on different domain you will get exception in the script. By default CORS are disabled in ASP.NET bot you can easily enable them just by modifying web.config for IIS7 and newer versions pf IIS. Sun, 22 Mar 2015 04:34:12 -04002015-03-22T04:34:12-04:009687https://dejanstojanovic.net/aspnet/2015/march/styles-and-images-in-app_offlinehtml-file/.NETStyles and images in app_offline.htm fileFrom time to time we all need to do some maintenance to our websites. ASP.NET has nice integrated feature to put your website online while you are updating files and librariesThu, 19 Mar 2015 09:00:17 -04002015-03-19T09:00:17-04:009685https://dejanstojanovic.net/aspnet/2015/march/generate-zip-file-on-the-fly-in-aspnet-mvc-application/.NETZip whole folder on the fly in ASP.NET MVC applicationGenerating Zip archives has always been a great thing if you need to generate different content for the request depending on some parameters. In case you need to return multiple files this is one approach to go withTue, 17 Mar 2015 07:22:11 -04002015-03-17T07:22:11-04:009679https://dejanstojanovic.net/javascript/2015/march/detect-when-file-download-request-is-finished-with-jquery/JavaScriptDetect when file download request is finished with jQueryRecently I started a small free service app for extracting icons from application files .exe and .dll. It is called IconExtract and it is hosted at http://iconextract.dejanstojanovic.net/ It basically takes application file you submit, extracts icons and returns them zipped, so beside long running upload there is some processing on the back-end when file is uploaded as well. Sun, 15 Mar 2015 00:30:12 -04002015-03-15T00:30:12-04:009678https://dejanstojanovic.net/aspnet/2015/march/image-thumbnail-html-helper-with-image-caching-for-the-perforance/.NETImage thumbnail Html helper with image caching for the perforanceCreating image thumbnail on the fly is pretty easy in ASP.NET whether you are still using WebForms or MVC. There is even a methods introduced in .NET 4.5 framework for generating thumbnail image from a Bitmap class instance. You can easily create and action in a controller and generate and return thumbnail image on the flyThu, 12 Mar 2015 11:02:36 -04002015-03-12T11:02:36-04:009677https://dejanstojanovic.net/sql/2015/march/reducing-the-number-of-stored-procedures-for-the-application/SQL/T-SQLReducing the number of Stored Procedures for the ApplicationNowadays, in the years of ORM, barely anyone thinks about stored procedures, but they are still there and accessing and reading data with ADO and SqlDataReader ist still  the fastest way. Stored procedures are validated, parsed and compiled in SQL server, so these steps are not required to be performed versus plaint text query (which is what entity framework generates for accessing data). Thu, 12 Mar 2015 04:59:18 -04002015-03-12T04:59:18-04:009672https://dejanstojanovic.net/javascript/2015/march/the-ways-of-loading-javascript-files-onto-your-page/JavaScriptThe ways of loading JavaScript files onto your pageRecently I was working on speeding up my website. As a reference I user Google PageSpeed Insights. There were few things, but among them was one that was that really poked my eyesTue, 03 Mar 2015 22:34:22 -05002015-03-03T22:34:22-05:009670https://dejanstojanovic.net/aspnet/2015/march/enabling-gzip-and-deflate-compression-from-aspnet-code/.NETEnabling GZip and Deflate compression from ASP.NET codeHTTP compression is a simple way to improve site performance and decrease bandwidth, with no configuration required on the client side. If you test your website through Google PageSpeed Insights, HTTP compression will be one of the points recommended to be used to increase website performance. Luckily for .NET developers IIS supports it out of the boxTue, 03 Mar 2015 09:51:33 -05002015-03-03T09:51:33-05:009669https://dejanstojanovic.net/umbraco-cms/2015/march/accessing-umbracohelper-in-httphandler-request/Umbraco CMSAccessing UmbracoHelper in HttpHandler requestIf you were planning to create sitemap.xml in Umbraco, you most probably were doing it with HttpHandler. This was fine until Umbraco version 6.2.2. If your website was running in lower version, most probably after update your HttpHandler were crashing since UmbracoContext.Current returns null. Mon, 02 Mar 2015 09:02:44 -05002015-03-02T09:02:44-05:009666https://dejanstojanovic.net/aspnet/2015/march/easier-manipulation-with-ienumerable-objects/.NETEasier manipulation with IEnumerable objectsWorking with any collection which implements IEnumerable is pretty easy in C#, plus if you are using LINQ you can easily manipulate with collection data. Recently I was doing some filtering with some in-memory collections and I had to check whether one collection contains same elements as some other collection with elements of the same typeMon, 02 Mar 2015 02:20:31 -05002015-03-02T02:20:31-05:009665https://dejanstojanovic.net/aspnet/2015/march/super-lightweight-data-access-layer-returning-models-from-ado/.NETSuper lightweight Data Access Layer returning models from ADOEntity framework is an awesome tool for working with database in .net, but sometime you have to get back to old fashion ADO for the performances. The bad thing is that as soon as you get back to ADO, you have to deal with SqlDataReader, DataTable and DataSet classesSun, 01 Mar 2015 08:47:58 -05002015-03-01T08:47:58-05:009661https://dejanstojanovic.net/sql/2015/february/transform-comma-seperated-string-to-rows/SQL/T-SQLTransform comma seperated string to rows in SQL ServerPassing complex data to and from stored procedures has always been a tricky one. The most elegant way to pass values to a stored procedure is to use  predefined data types in SQL ServerTue, 24 Feb 2015 06:43:33 -05002015-02-24T06:43:33-05:009659https://dejanstojanovic.net/sql/2015/february/migrate-stored-procedures-across-databases/SQL/T-SQLMigrate stored procedures across databasesWhen working on an app you create all your stored procedures, functions, tables, view and other objects in a development database (or t least it should be like that). A small but annoying problem occurs when you have to migrate your stored procedures to test or production database. Imagine during development you had let's say 20 stored proceduresWed, 18 Feb 2015 07:01:22 -05002015-02-18T07:01:22-05:009654https://dejanstojanovic.net/aspnet/2015/february/managed-extensibility-framework-quick-start/.NETManaged Extensibility Framework (MEF) quick startManaged Extensibility Framework or MEF is a library introduced in .NET Framework 4 which allows developers to easily create plugin based applications. It lives in System.ComponentModel.Composition namespace and before start working with MEF reference to this assembly needs to be added in a project.It is basically an implementation of IoC (Inversion of Control) pattern with few core functionalities such as assembly loadingMon, 09 Feb 2015 21:43:12 -05002015-02-09T21:43:12-05:008651https://dejanstojanovic.net/aspnet/2015/february/random-element-of-ienumerablearray/.NETRandom element of IEnumerable/ArrayI don't work with random values very often but recently I had to write some small function that returns random value from an array. It sounded like a good idea to write it as an extension method to make it reusable for other projectsFri, 06 Feb 2015 10:13:50 -05002015-02-06T10:13:50-05:008650https://dejanstojanovic.net/aspnet/2015/february/concurrentdictionary-vs-hashtablesynchronized/.NETConcurrentDictionary vs Hashtable.SynchronizedBasically all Dictionary collections in .NET internally implement Hashtable wrapped, so in terms of mechanism they are pretty much the same. The difference is that Dictionary exposes strong types while Hashtable uses object-object keyvalue pair which is much harder to work with because you need to know what is the actual type of the object stored in a key or value. Often casting will probably be requiredThu, 05 Feb 2015 06:47:09 -05002015-02-05T06:47:09-05:008641https://dejanstojanovic.net/aspnet/2015/february/convert-string-to-any-type-that-implements-tryparse-method/.NETConvert string to any type that implements TryParse methodIn many cases serialized data is returned in a form of string although the actual type of data is different. The problem begings when you want to use data in it's original type becaus direct cast is not allowed in C# as it is in VB.net. This is why you have to use TryParse and safely parse the value to it's original typeMon, 02 Feb 2015 02:15:06 -05002015-02-02T02:15:06-05:008640https://dejanstojanovic.net/aspnet/2015/february/creating-visual-studio-projecttemplate-vsix-package/.NETCreating Visual Studio ProjectTemplate VSIX packageIf you often have projects which setup is pretty much the same you might consider creating ProjectTemplate for Visual Studio.It speeds up development for the project setup, adding references, default configuration .config, content files... Before you start make sure that you have installed Microsoft Visual Studio 2013 SDK (http://www.microsoft.com/en-us/download/details.aspx?id=40758) and Nuget Package Explorer (http://npe.codeplex.com/)I also attached a small dummy project just to help understanding what is written in this article.Skipping to hands on code is always more helpful and faster for me to, so if you are bored by reading, download the attached .7zfile and explore itSun, 01 Feb 2015 08:21:10 -05002015-02-01T08:21:10-05:008631https://dejanstojanovic.net/aspnet/2015/january/custom-configuration-section-with-intelisense/.NETCustom configuration section with intelisenseConfig files are really useful and allow you to store some setting values without having to hard-code them. It provides out of the box configuration utility which is very flexible, but because of its flexibility, it has some drawbacks as wellThu, 22 Jan 2015 21:32:48 -05002015-01-22T21:32:48-05:008630https://dejanstojanovic.net/aspnet/2015/january/set-entry-assembly-in-unit-testing-methods/.NETSet entry assembly in Unit testing methodsRecently I started writing unit tests for a small project I keep in my visualstudio online TFS repository. After few test done I run into an issue. Since this project heavily relies on Reflection and dynamic assembly loading, main class constructor at one point is calling Sun, 18 Jan 2015 23:32:02 -05002015-01-18T23:32:02-05:008626https://dejanstojanovic.net/aspnet/2015/january/avoiding-high-processor-load-in-long-running-loops/.NETAvoiding high processor load in long running loopsWhen having a long running loop which you are not sure when it is going to end you will probably have to create a loop in a separate loop and on every iterration you will check whether some condition is true and exit the loop. Let's say you want to execute some piece of code after some specific time, let's say after one minute or everyday at specific time (common scenario in windows services). You can do it really simple with Timer class and just few lines of code as the code below. Sun, 18 Jan 2015 01:59:40 -05002015-01-18T01:59:40-05:008624https://dejanstojanovic.net/aspnet/2015/january/deserializing-json-to-anonymus-type-in-c/.NETDeserializing JSON to anonymus type in C#JSON is really easy to use and it really boosts performances since it is a lot lighter than XML and SOAP. Sometime it can be really annoying having to create POCO class every time you need to deserialize JSON value passed from client side in ASP.NET web applications. During extending project functionality this number of POCO classes can significantly grow to that matter that you have a bunch of classes for even the simplest task you have to do with JSON value. Wed, 14 Jan 2015 07:14:04 -05002015-01-14T07:14:04-05:008619https://dejanstojanovic.net/aspnet/2015/january/application-plugin-host-with-assembly-caching-and-auto-reloading/.NETApplication plugin host with assembly caching and auto reloadingFew moths ago I  wrote and article about simple way to implement plugin architecture in C# simple plugin host application approach. This approach is great for desktop applications because when you for example need to update (which means replace the plugin dll) you can easily close the app and start it again and it will pickup new codeMon, 05 Jan 2015 03:58:27 -05002015-01-05T03:58:27-05:008618https://dejanstojanovic.net/aspnet/2015/january/javascript-eval-function-equivalent-in-c/.NETJavaScript Eval function equivalent in C#Probably who ever was working on some complicated dynamic client-side JavaScript used at least once eval functional in JavaScript. Basically this function executes the code which is passed to it as  parameterSun, 04 Jan 2015 09:41:56 -05002015-01-04T09:41:56-05:008611https://dejanstojanovic.net/javascript/2015/january/facebook-album-browser-jquery-plugin/JavaScriptFacebook Album Browser JQuery PluginReponsive jQuery plugin for browsing public albums of a Facebook account. Plugin is suitable for both desktop and mobile websites.Tue, 30 Dec 2014 03:18:28 -05002014-12-30T03:18:28-05:008608https://dejanstojanovic.net/aspnet/2014/december/one-way-fire-and-forget-action-in-wcf/.NETOne way, fire and forget action in WCFIn case you are building a web app that needs to perform some complex or long running task, for sure you would't want that task to slow down your website or web application. For example you have a database of growing number of members on your website and you want to send a notification after you published some page on the website. Imagine you have 10,000+ members and that you are composing different message for each of them based on their account information and then sending an email with notification message. Fri, 26 Dec 2014 06:03:47 -05002014-12-26T06:03:47-05:008604https://dejanstojanovic.net/aspnet/2015/january/aspnet-web-application-security-check-list/.NETASP.NET web application security check listThere are several things to be taken care of during development and before deployment to keep you online web app tip top regarding performance and security. 1. Logging informations Sun, 21 Dec 2014 10:32:09 -05002014-12-21T10:32:09-05:008603https://dejanstojanovic.net/aspnet/2014/december/team-foundation-server-power-tools/.NETTeam Foundation Server Power ToolsTo be honest I really like Tortoise SVN. It is so easy to work with it from the file system and it is so easy to commit your code changes to public repositories on GitHub. Unfortunately, if you would like to keep your code somewhere safe in cloud and keep it private, for GitHub option you will not get it for free. Wed, 17 Dec 2014 03:25:32 -05002014-12-17T03:25:32-05:008600https://dejanstojanovic.net/aspnet/2014/december/separate-debug-and-release-code-in-c/.NETSeparate Debug and Release code in C#Basic functionality of your code does what it should do regardless of whether it is compiled in Debug of Release mode. Only differences might be related to debugging the code and tracing errors during debug. For sure you want more monitoring during the development (debug mode), so you would probably add some sort of logging. Tue, 16 Dec 2014 23:12:05 -05002014-12-16T23:12:05-05:008599https://dejanstojanovic.net/aspnet/2014/december/restrict-image-and-css-hotlinking-of-your-aspnet-website/.NETRestrict image and CSS hotlinking of your ASP.NET websiteI did not rely how important to restrict hot-linking until one day my friend came to me and told me that he has to pay additional money for the bandwidth on his website. He was surprised that he reached bandwidth quota limit. It was weird, but after some logging of requests coming to a website we realized that most of the requests were initiated from some other websiteTue, 16 Dec 2014 04:48:43 -05002014-12-16T04:48:43-05:008596https://dejanstojanovic.net/aspnet/2014/december/windows-scheduled-task-vs-windows-service/.NETWindows Scheduled Task vs Windows ServiceFrom time to time you have a need to implement some maintainance opration for your application server. Whether it is just a simple temporary file deleting pr something more complicated. Two most common ways to do this are either using Tue, 09 Dec 2014 10:26:23 -05002014-12-09T10:26:23-05:008595https://dejanstojanovic.net/aspnet/2014/december/the-x-frame-options-response-header/.NETThe X-Frame-Options response headerI found this header option repeating in many guidelines for securing the web application. By adding these headers to response, it restricts browser to load your page into an iFrame tag. Thu, 04 Dec 2014 04:38:12 -05002014-12-04T04:38:12-05:008593https://dejanstojanovic.net/javascript/2014/december/css-media-queries-instead-of-javascript-code/JavaScriptCSS Media Queries instead of JavaScript codeBefore CSS3 coming out, if you needed to change the layout programatically when window size is changed you would have to write a small JavaScript or JQuery to handle window resize event and perform some action on the DOM to addapt your layout. In case you would use JQuery (which is most of the cases as I do not remember last time I wrotw plain JavaScript code) you would have to hook to window resize event and handle every resize. Based on your condition you would apply some CSS to specific element or strip style from it. Tue, 02 Dec 2014 22:25:12 -05002014-12-02T22:25:12-05:008587https://dejanstojanovic.net/javascript/2014/november/testing-facebook-apps-with-special-permissions/JavaScriptTesting Facebook apps with special permissionsSocial networks are in an expansion and more and more they are becoming part of the applications, especially online applications. Even .NET framework included authentication with social networks built in as an out of the box feature of .NET platform. However as social networks evolve they are changing mostly in the area of security and user data privacy. Sat, 22 Nov 2014 21:21:08 -05002014-11-22T21:21:08-05:008585https://dejanstojanovic.net/aspnet/2014/november/generating-html-structure-string-in-c/.NETGenerating HTML structure string in C#String hardcoding it the worst way to generate your HTML. It makes code non-maintainable and hard to read. Lately in June I wrote an article how to generate HTML string without hard coding the string and using concatenation or string formatWed, 19 Nov 2014 08:54:23 -05002014-11-19T08:54:23-05:008583https://dejanstojanovic.net/aspnet/2014/november/adding-extra-info-to-an-image-file/.NETAdding extra info to an image fileI was always wondering where are additional properties for the image stored. Simply, when you click right click on the image in Windows and go to properties, in tab Details there are some more info than just file size and image dimensions.   Wed, 19 Nov 2014 04:27:47 -05002014-11-19T04:27:47-05:008579https://dejanstojanovic.net/javascript/2014/november/working-with-canvas-on-images-loaded-from-different-domain/JavaScriptWorking with canvas on images loaded from different domainRecently I'we been working with HTML canvas by using cropper jQuery plugin http://fengyuanchen.github.io/cropper. It was working fine until I had to load images from Facebook. As soon as I loaded image from facebook, script was crashing with a security error: Mon, 17 Nov 2014 05:07:48 -05002014-11-17T05:07:48-05:008574https://dejanstojanovic.net/aspnet/2014/november/using-lazy-in-c/.NETUsing Lazy<T> in C#Although Lazy keyword and functionality was introduced in .net framework 4.0, not many people are using. It is not something that was not possible to be done later, but now it is available only oin one line. Basicaly what Lazy keyword enables is to create an instance only when it is invoked for the first time. Wed, 05 Nov 2014 01:05:55 -05002014-11-05T01:05:55-05:008570https://dejanstojanovic.net/aspnet/2014/october/simple-plugin-host-application-approach/.NETSimple plugin host application approach in C#A lot of, especially desktop applications implement plugin approach in order to make application more expendable and allow other vendors to include their specific functionality related to applications with plugins. Usually plugins are available from some sort of repository from which user can select and download them directly to applicationThu, 30 Oct 2014 10:52:50 -04002014-10-30T10:52:50-04:008568https://dejanstojanovic.net/aspnet/2014/october/the-server-committed-a-protocol-violation-section-responsestatusline/.NETThe server committed a protocol violation. Section=ResponseStatusLineRecently I was adding GitHub project section to my blog when I run into the following exception "The server committed a protocol violation. Section=ResponseStatusLine" After some time of Google-ing I found few solutions, but the most simplest one was actually the best oneSun, 26 Oct 2014 23:14:07 -04002014-10-26T23:14:07-04:008566https://dejanstojanovic.net/aspnet/2014/october/persistent-authentication-cookie-and-autologin/.NETPersistent authentication cookie and autologinASP.NET comes with built in login form both for WebForms or MVC, but sometimes you have to do it in a custom manner where permanent authentication cookie needs to be set from your code following your business logic. First thing you have to do is to set expiration time for authentication cookie in web.config. This is for done first to make sure that your cookie does not expire during your testing. Mon, 20 Oct 2014 04:36:03 -04002014-10-20T04:36:03-04:008565https://dejanstojanovic.net/aspnet/2014/october/maintaining-same-session-with-separate-web-requests-from-c-code/.NETMaintaining same session with separate web requests from C# codeRecently I started a small project for image optimization which relies on public image optimization services available online. For now it supports Yahoo SmushIt and Compressor.io services, but it will be extended over the time. Project is open-source and hosted at GitHub https://github.com/dejanstojanovic/ImageOptimization. Sun, 19 Oct 2014 01:39:04 -04002014-10-19T01:39:04-04:008563https://dejanstojanovic.net/aspnet/2014/october/getting-social-network-access-token-from-c-backend/.NETGetting social network access token from C# backendMost popular social networks such is Facebook and Google+ are providing authentication for web applications with fancy javascript pop-ups. However this approach might not work in all browsers and most likely not on every device. For example this approach does not work on iPhone or iPad because browser itself does not allow pop-upsThu, 09 Oct 2014 02:58:29 -04002014-10-09T02:58:29-04:008559https://dejanstojanovic.net/aspnet/2014/september/honeypot-implementation-in-mvc/.NETHoneypot implementation in ASP.NET MVCYou can find a bunch of articles on internet about HONEYPOT implementation on web pages, but in short it is a replacement for CAPTCHA anti-bot security. In CAPTCHA scenario, user needs to enter hardly recognizable characters in order to prove that he is not a bot trying to submit dataMon, 22 Sep 2014 04:44:43 -04002014-09-22T04:44:43-04:008553https://dejanstojanovic.net/aspnet/2014/september/change-requestform-collection-on-the-fly/.NETChange Request.Form collection on the flyData from form are sent to backend (whether code behing of page in WebForms or Controller Action in MVC) in Request.Form property. It is oragnized as collection of name and value and can be easily access by name. In some extreme cases, you need to make some modifications to posted form data. Thu, 18 Sep 2014 21:00:51 -04002014-09-18T21:00:51-04:008552https://dejanstojanovic.net/aspnet/2014/september/access-auto-property-backing-field-with-reflection/.NETAccess auto property backing field with reflectionUsing reflection you can easily access any property, filed, methods, pretty much anything of any type in .NET. Reflection is never the most elegant way to do something, but sometime you just have to do it. In older versions of C#, to declare a simple property in a class you would have to declare a private field which will be exposed by the property outside the class Thu, 18 Sep 2014 12:46:35 -04002014-09-18T12:46:35-04:008551https://dejanstojanovic.net/aspnet/2014/september/obtaining-access-token-from-googleplus-api-in-non-spa-web-application/.NETObtaining access token from Google+ API in non SPA web applicationRecently I was trying to use Google+ OAuth api for authenticating with Google+ and fetch some user basic info such as name and email. Wed, 17 Sep 2014 04:06:06 -04002014-09-17T04:06:06-04:008548https://dejanstojanovic.net/umbraco-cms/2014/september/same-page-language-switching-in-umbraco/Umbraco CMSSame page language switching in UmbracoWhen we build multi-language website, we usually create two root elements which represent different language websites. To switch the language you just need to add a link to other root elements which represent other languages of the website. With this approach, when you switch language you will end up at homepage of the language regardless which page you were viewing. Sun, 14 Sep 2014 08:56:44 -04002014-09-14T08:56:44-04:008546https://dejanstojanovic.net/aspnet/2014/september/bypass-ssl-certificate-validation/.NETBypass SSL certificate validationIt is a common thing that some of your application functionalities depend on an external HTTPS endpoint. However, renewal of SSL certificate for the external party is out of your control and you have to rely on the third party that certificate will be renewed on timeSat, 13 Sep 2014 20:24:31 -04002014-09-13T20:24:31-04:008532https://dejanstojanovic.net/javascript/2014/september/extension-method-equivalents-in-javascript/JavaScriptExtension method equivalents in JavaScriptFor someone who works in C#, extension methods are one really useful feature introduced in .NET framework. I use extension methods a lot because they are so nicely integrated with intellisense and you can access them really easy. Thu, 11 Sep 2014 05:20:55 -04002014-09-11T05:20:55-04:008530https://dejanstojanovic.net/aspnet/2014/september/filesize-to-proper-display-string/.NETFilesize to proper display stringHow many times you had to display file size on your web page? Pretty much every time you might have the same issue with recalculating size to KB or MB. I caught myself doing this for so many times over and over, so finally I decided to write a piece of code for that. Tue, 09 Sep 2014 21:41:00 -04002014-09-09T21:41:00-04:008529https://dejanstojanovic.net/aspnet/2014/september/the-fastest-way-to-export-data-to-excel/.NETThe fastest way to export data to ExcelIt is not so rare that you have to provide some sort of export of your data stored in database. I have a feeling that clients really like to have that functionality, probably because they are more comfortable with Excel than with any other tool. First thing that might pop to your mind is to add a reference to Office library, but that would require that you have Office on the hosting machine which might not be the case as most of hosts do not have it. Mon, 08 Sep 2014 06:47:00 -04002014-09-08T06:47:00-04:008528https://dejanstojanovic.net/aspnet/2014/september/simple-object-mapper-using-reflection/.NETSimple object mapper using reflectionDealing with models and POCO classes in MVC sometimes require to map properties from one object to another because they have some properties of the same name and type. This also can be a case when you are loading a model class from some other source and you need to transform it to your type with some additional properties, but also a bunch of properties with values from the source object instance. Sat, 06 Sep 2014 11:21:21 -04002014-09-06T11:21:21-04:008527https://dejanstojanovic.net/umbraco-cms/2014/september/getting-cropped-image-the-smart-way/Umbraco CMSGetting cropped image the smart wayI noticed that some of the content managers keep complaining about the quality and size of cropped images. If you lower down quality, file is smaller but in some cases it gets blurry with quirks which comes from compression applied to a file. Let's face it, image cropper is not Photoshop with all options for image optimizationThu, 04 Sep 2014 20:54:54 -04002014-09-04T20:54:54-04:008525https://dejanstojanovic.net/aspnet/2014/september/check-whether-you-are-getting-cached-content-in-mvc-website/.NETCheck whether you are getting cached content in MVC websiteIt happens from time to time that you publish some content from back-end, but on the website you still see the old content. Reasons for this may be different: Wed, 03 Sep 2014 23:13:46 -04002014-09-03T23:13:46-04:008524https://dejanstojanovic.net/aspnet/2014/september/single-file-deployment-concept-in-aspnet-with-webapi/.NETSingle file deployment concept in ASP.NET with WebAPIAs much as this sound new to you, it actually isn't. If you worked on any Windows From application in .NET you had an option to embedded files in your form like images, icons and even sounds and videos. This made deployment a lot easier because you only have to deploy one .exe file. Wed, 03 Sep 2014 20:26:32 -04002014-09-03T20:26:32-04:008512https://dejanstojanovic.net/aspnet/2014/august/shrinking-and-optimizing-linq-expressions-with-anonymous-types-and-anonymous-methods/.NETOptimizing LINQ expressions with anonymous types and methodsWhen LINQ was announced in .NET framework 3.5 I was a bit skeptic because it look a bit odd to me on the first look. Writing queries in C#, just did not look right to me. Anyway, not all the things introduced in .NET had long lifeSat, 30 Aug 2014 20:35:16 -04002014-08-30T20:35:16-04:008506https://dejanstojanovic.net/umbraco-cms/2014/august/fastest-way-to-return-json-result-from-a-controller/Umbraco CMSFastest way to return JSON result from a controllerRecently I had to develop a form on a page which loads secondary dropdown list items based on selection in a primary dropdown list. Because secondary list items are basically children elements of the one selected in primary I just had to run through all children and just return text-value pair object to JavaScript to populate secondary dropdown list. Wed, 27 Aug 2014 02:50:07 -04002014-08-27T02:50:07-04:008504https://dejanstojanovic.net/umbraco-cms/2014/august/nesting-dictionary-items-to-create-lists/Umbraco CMSNesting Dictionary items to create listsRecently I wrote an article about workaround for storing lists in Umbraco. I did some googling and Umbraco API exploring since then I found another solution for lists in Umbraco. This solution is relying to Umbraco DictionaryMon, 25 Aug 2014 01:14:19 -04002014-08-25T01:14:19-04:008501https://dejanstojanovic.net/aspnet/2014/august/faking-browser-client-in-httpwebrequest/.NETFaking browser client in HttpWebRequestUsing HttpWebRequest to fetch some data in your code from web is the easiest way to do it. However some web locations have restrictions to all only requests which come from browsers. Performing a normal HttpWebRequest will return 403 status code (HTTP 403 - Wikipedia) which means forbidden accessFri, 22 Aug 2014 07:40:45 -04002014-08-22T07:40:45-04:008499https://dejanstojanovic.net/umbraco-cms/2014/august/dictionary-lists-in-umbraco/Umbraco CMSDictionary lists in UmbracoUmbraco implementation of localized values is based on Dictionary which is in settings section of Umbraco back-end. This works pretty fine in case you need to display only string values but does not work localized lists. For example you might want to have country list for your contact form on your websiteSat, 16 Aug 2014 09:44:22 -04002014-08-16T09:44:22-04:008496https://dejanstojanovic.net/aspnet/2014/august/using-googlemaps-route-api-to-get-accurate-distance/.NETUsing GoogleMaps Directions API to get accurate distanceIn situations where distance between two geo coordinates needs to be found most of the people are using mathematical function to do this. However there is a major disadvantage in using this methodThu, 14 Aug 2014 23:55:52 -04002014-08-14T23:55:52-04:008495https://dejanstojanovic.net/aspnet/2014/august/restrict-access-to-an-mvc-action-or-controller-based-on-ip-address/.NETRestrict Access to an MVC Action or Controller based on IP addressWhen you are developing a back-end web application, you might want to restrict access only to people who are working in the company which is maintaining the content or any other operations in the back-end and allowing public access only for the public, usually read-only content. This means you still have to leave some parts of your application public and for some you need to restrict access for the people outside of a network (certain IP range). Mon, 11 Aug 2014 22:27:50 -04002014-08-11T22:27:50-04:008493https://dejanstojanovic.net/umbraco-cms/2014/august/best-practice-tips-for-large-scale-umbraco-websites/Umbraco CMSBest practice tips for large scale Umbraco websitesUmbraco is a great CMS, it simple, easily extendible and most important it is free. However, it is not build for large scale websites, since presentation and back-end are on the same machine and all published content is stored in AppData/umbraco.config file. This is good because it can be easily cached and database read is reducedThu, 07 Aug 2014 09:29:06 -04002014-08-07T09:29:06-04:008492https://dejanstojanovic.net/umbraco-cms/2014/august/automatic-property-population-when-node-created/Umbraco CMSAutomatic property population when node createdFor pretty much every website I built in Umbraco, there is some sort of title property for page document type. Either it is a title for navigation in breadcrumbs or menu or main h1 page title. Usually some of these properties need to be mandatory and in most cases they are the same as the name of the node in content, but still, you have to keep ability to override the value with these properties. Mon, 04 Aug 2014 04:19:06 -04002014-08-04T04:19:06-04:008488https://dejanstojanovic.net/javascript/2014/july/testing-mobile-website-client-side-functionality-on-desktop/JavaScriptTesting mobile website client side functionality on desktopRecently I have posted an article about new HTML5 features for mobile devices where some of the new JavaScript APIs are described. If you decide to apply any of these new cool features on your mobile website you would first want to test them before you publish them on the real website. You can always expose the website to you mobile device and navigate, but it really takes additional time and after 10th time you would really get annoyed by doing this. Thu, 31 Jul 2014 09:10:09 -04002014-07-31T09:10:09-04:008486https://dejanstojanovic.net/javascript/2014/july/html5-javascript-api-for-mobile-devices/JavaScriptHTML5 JavaScript API for mobile devicesHTML5 is awesome for desktop websites and believe it or not, even more awesome for mobile devices. In the following article, I'll show you few HTML5 APIs which can be invoked from JavaScript which directly interact with your mobile device, so let's start. Geolocation API Wed, 30 Jul 2014 02:21:19 -04002014-07-30T02:21:19-04:007490https://dejanstojanovic.net/javascript/2014/july/use-github-for-hosting-js-and-css-files/JavaScriptUse GitHub for hosting JS and CSS filesRecently I've started JQuery plugin project on GitHub and decided to provide examples via JSFiddler. I could easily take latest files and host it on the same host as this blog but that would make a headache for me as I would have to update files on my host as soon as I update file in GitHub. So I googled a little bit and found a solutionMon, 28 Jul 2014 10:23:49 -04002014-07-28T10:23:49-04:007483https://dejanstojanovic.net/aspnet/2014/july/synchronous-vs-asynchronous-mvc-controllers/.NETSynchronous vs asynchronous MVC controllersMaybe you did not know but asp.net applications have limited number of threads available to process requests. This value is set in your machine.config in configuration/system.web/processModel node. This file is located at Thu, 03 Jul 2014 00:56:17 -04002014-07-03T00:56:17-04:007473https://dejanstojanovic.net/aspnet/2014/june/database-change-notifications-in-aspnet-using-websocket/.NETDatabase Change Notifications in ASP.NET using WebSocketDatabase table changes are usually not displayed right away in an application, escecially if it is a web application. With HTML5 and Web API that is about to changeSun, 29 Jun 2014 23:22:01 -04002014-06-29T23:22:01-04:007466https://dejanstojanovic.net/aspnet/2014/june/async-file-upload-with-mvc4/.NETAsync file upload with MVC4Uploading files with form submit on web page, especially large file requires user to wait for browser until file is uploaded. This does not produce very nice user experience as user needs to wait without any notification for file to be uploadedSat, 28 Jun 2014 22:26:17 -04002014-06-28T22:26:17-04:007464https://dejanstojanovic.net/aspnet/2014/june/websocket-in-mvc4/.NETUsing WebSocket in MVC4Ajax is really cool. You can pull your data without refreshing the whole page, but increasing user experience and downsizing bandwidth for website. If you have some live data which is changing really often, the best way to display it on website is to use pulling mechanismWed, 25 Jun 2014 22:19:28 -04002014-06-25T22:19:28-04:006461https://dejanstojanovic.net/javascript/2014/june/goodbye-jquery-color-picker-plugins/JavaScriptGoodbye JQuery color-picker pluginsA lot of browser these days support HTML file but not all of them in the same percentage. There are really cool stuff in there which makes developers and designers life a lot easierTue, 17 Jun 2014 20:21:13 -04002014-06-17T20:21:13-04:006459https://dejanstojanovic.net/aspnet/2014/june/returning-an-image-in-web-api-method-with-fallback-result-image/.NETReturning an image in Web API method with fallback result imageImagine the following scenario. You are building a social network like website and you need to create your own API to enable other developers to integrate with your web location really easy. One of the things that most popular social networks now provide in the API is providing profile imageMon, 16 Jun 2014 22:32:24 -04002014-06-16T22:32:24-04:006457https://dejanstojanovic.net/aspnet/2014/june/getting-systemdrawingimagingimageformat-from-a-string/.NETGetting System.Drawing.Imaging.ImageFormat from a stringImages are part of pretty much any application especially web. Not so rarely they need to be protected or exposed from a different sources which cannot be accessed directly with just typing URL to it's actual location. It all comes down to writing image bytes to an output streamSun, 15 Jun 2014 22:35:24 -04002014-06-15T22:35:24-04:006455https://dejanstojanovic.net/javascript/2014/june/request-different-data-type-from-web-api-with-jquery/JavaScriptRequest different data type from Web API with JQueryIn my previous article Different data type in Web API response of the same method I described how to get different response with HttpWebRequest in C#. Here I will demonstrate how to achieve the same thing but in JQuery client side codeFri, 13 Jun 2014 08:01:09 -04002014-06-13T08:01:09-04:006453https://dejanstojanovic.net/aspnet/2014/june/different-data-type-in-web-api-response-of-the-same-method/.NETDifferent data type in Web API response of the same methodWeb API restful services are very flexible and they return different data format (JSON or XML) depending on accept type header value from your browser (or other client). However this is not always so precise so sometime you have to force return typeThu, 12 Jun 2014 04:22:52 -04002014-06-12T04:22:52-04:006450https://dejanstojanovic.net/javascript/2014/june/optimized-usage-of-googlemaps-api/JavaScriptOptimized usage of GoogleMaps APIGoogleMaps are very useful to show location on your page. It is not a big problem if you have only one map, but in some cases you might have to add few maps on the page. As many maps you want to display you only need to reference API onceWed, 11 Jun 2014 21:29:33 -04002014-06-11T21:29:33-04:006445https://dejanstojanovic.net/umbraco-cms/2014/june/aggregating-rss-feeds-from-umbraco-content/Umbraco CMSAggregating RSS feeds from Umbraco contentRSS stands for Really Simple Syndication. It's an easy way for you to keep up with news and information that's important to you, and helps you avoid the conventional methods of browsing or searching for information on websites. Umbraco stores it's published content in XML format, so exposing website data is really easyTue, 10 Jun 2014 05:19:12 -04002014-06-10T05:19:12-04:006444https://dejanstojanovic.net/aspnet/2014/june/generating-html-string-in-c/.NETGenerating HTML string in C#From time to time you get to the point where you have to generate some HTML in C# code. Of course, the easier way is to concatenate string and return that as a result of a method. This is not the most elegant solution and it is only fine for some short string. Sat, 07 Jun 2014 21:51:08 -04002014-06-07T21:51:08-04:006441https://dejanstojanovic.net/umbraco-cms/2014/june/serving-embedded-resources-through-webapi-in-umbraco/Umbraco CMSServing embedded resources through WebAPI in Umbraco Recently I've deploying GoogleMap Editor package to Umbraco community. During development I realized that package will have to include script, some html templates, images... I had no problem with that but when it came to actual package build I realized that I will have to deal with bunch of files and even during development, so se some changes which were not dll related I had to restart app by touching web.config. Fri, 06 Jun 2014 00:15:57 -04002014-06-06T00:15:57-04:005436https://dejanstojanovic.net/umbraco-cms/2014/may/fetching-image-cropper-cropped-file-path/Umbraco CMSFetching image cropper cropped file pathImageCropper datatype was once part of uComponents, but because it is so usefull, it is now included into standard Umbraco instalation. However as much it is useful, I could not find the way to get cropped image file properly with anything that was shipped with Umbraco installation. Therefore I decided to write my own extension and to make life easier while working with ImageCropper in Umbraco. Fri, 30 May 2014 11:22:20 -04002014-05-30T11:22:20-04:005417https://dejanstojanovic.net/aspnet/2014/may/enumerable-tips-tricks/.NETEnumerable Tips & Tricks with String and IntSystem.Linq.Enumerable is a core of LINQ magic. Most of the functions we use in a daily basis for anything we write with sequence, but what is really interesting is that methods from this class can be used for some tricky operations on strings and numbers and make them one line instead of loops. Wed, 28 May 2014 01:46:35 -04002014-05-28T01:46:35-04:005416https://dejanstojanovic.net/aspnet/2014/may/forcing-accept-type-for-webapi-call/.NETForcing accept type for WebApi callOne of the coolest things of WebApi is that adapts to accept type sent in request header. This header value depends on a client. Based on this WebApi will serve different formats of data (XML/JSON). Tue, 27 May 2014 22:02:11 -04002014-05-27T22:02:11-04:005415https://dejanstojanovic.net/aspnet/2014/may/extending-webforms-page-class-for-registering-stylesheet-include/.NETExtending WebForms Page class for registering stylesheet includeI recently started working on an Umbraco package for GoogleMap manipulation. Since initial version of package is planned only for Umbraco 6 I decided to use WebuserControl for creating a package custom datatype. It means that for one document type I might have multiple control instances on the page. Tue, 27 May 2014 08:55:46 -04002014-05-27T08:55:46-04:005413https://dejanstojanovic.net/javascript/2014/may/json-error-when-loading-html-content-with-ajax-using-$get/JavaScriptJSON error when loading HTML content with AJAX using $.getI'm currently working on a package for Umbraco which involves loading of some HTML forms dynamically with AJAX. Biggest part of the package relies on JavaScript, so everything in script has to be perfect in order to make package work properly. Therefore I started development of JavaScript library independetly of the rest of the package logicMon, 26 May 2014 21:08:27 -04002014-05-26T21:08:27-04:005412https://dejanstojanovic.net/umbraco-cms/2014/may/exposing-richtext-property-from-content-in-umbraco-web-api/Umbraco CMSExposing richtext property from content in Umbraco Web ApiAlmost every content page in your website will have one richtext property for adding rich content for the page. This allows you to add Macros so you can render dynamic content inside page content at custom places in the page itself. Thu, 22 May 2014 05:09:33 -04002014-05-22T05:09:33-04:005411https://dejanstojanovic.net/umbraco-cms/2014/may/hide-property-in-umbraco/Umbraco CMSHide property in UmbracoThere is no option for hiding a property in Umbraco. Simply, when you define a property for document type, it is assumed that you are going to use it. However, sometime you need to hide it for some specific condition, like level of document in a tree, or document type which might inherits some property which you do not want to use in inherited document typeSat, 17 May 2014 05:37:36 -04002014-05-17T05:37:36-04:005410https://dejanstojanovic.net/umbraco-cms/2014/may/optimized-media-serving-in-umbraco/Umbraco CMSOptimized media serving in Umbraco by creating media CDNLet's say you have multiple websites with different domains in one Umbraco instance. All websites will use the same media, but the catch is how will it serve them. For example the same image will be served to a browser with two different paths like the following: Thu, 15 May 2014 03:33:13 -04002014-05-15T03:33:13-04:005409https://dejanstojanovic.net/umbraco-cms/2014/may/reading-umbraco-dictionary-item-in-ajax-request/Umbraco CMSReading Umbraco dictionary item in Ajax requestYou probably had to make some Ajax call in your Umbraco website. This is really easy in versions star6ting from version six and aboveWed, 14 May 2014 01:31:09 -04002014-05-14T01:31:09-04:004401https://dejanstojanovic.net/javascript/2014/may/jquery-onchange-issue-in-ie8/JavaScriptJQuery .onchange issue in IE8Apparently IE8 and older versions of IE browsers do not support JQuery onchange event for checkboxes and radio buttons. If you are using this for handling this event, your script will fail, because these events will not be fired on IE8 or older IE. Instead of this you can add handler for onclick event which works fine in pretty much any browser. Tue, 06 May 2014 05:10:03 -04002014-05-06T05:10:03-04:004396https://dejanstojanovic.net/aspnet/2014/april/detecting-request-from-mobile-device/.NETDetecting request from mobile deviceMicrosoft made is easy to detect whether request to your web application is coming from mobile device or not by adding a property to Request class. Usage of this is Request.Browser.IsMobileDevice. This works pretty fine for most of mobile devices, but this property is based on list of mobile browsers which is configured in .NET framework itself. Mon, 28 Apr 2014 23:58:25 -04002014-04-28T23:58:25-04:004391https://dejanstojanovic.net/aspnet/2014/april/bitmap-manipulation-extension-methods/.NETBitmap manipulation extension methods for C#This is a class I used few years back for some image manipulation in C#. Over the years, I was adding more methods and code snippets I needed and some stuff I found on Internet, so it grow to a useful collection of Bitmap manipulation methodsSat, 26 Apr 2014 20:46:25 -04002014-04-26T20:46:25-04:004390https://dejanstojanovic.net/aspnet/2014/april/simple-configuration-class/.NETSimple configuration classVery often you need to store some settings in your configuration. Web.config files are designed for that but there are two things I found very annoying: Wed, 23 Apr 2014 20:32:35 -04002014-04-23T20:32:35-04:004382https://dejanstojanovic.net/umbraco-cms/2014/april/properties-your-page-document-type-must-have/Umbraco CMSProperties your page document type must haveThere are two properties which are not related directly to page content which are always useful to have on your document type which represent page on your website. 1. Hide in navigation Sat, 19 Apr 2014 07:17:11 -04002014-04-19T07:17:11-04:003378https://dejanstojanovic.net/umbraco-cms/2014/april/upload-multiple-custom-media-types/Umbraco CMSUpload multiple custom media typesYou probably often had to add some additional ptoperties to a media type. It is all fine untill you have to keep native media type and create inherited one with additional properties. Everything is fine untill you try to do drag and drop upload of mutiple filesWed, 16 Apr 2014 09:53:59 -04002014-04-16T09:53:59-04:003377https://dejanstojanovic.net/umbraco-cms/2014/april/image-cropper-auto-create/Umbraco CMSImage Cropper Auto CreateIt probably happend you often that you need to add image cropper to a page or custom media type. Right after you upload image cropper property does not generate cropped image file. You would have to save the page/media once againg, so that image cropper is initialized and cropped files are generated. Wed, 16 Apr 2014 08:52:25 -04002014-04-16T08:52:25-04:003365https://dejanstojanovic.net/umbraco-cms/2014/april/microsoft-live-writer-umbraco/Umbraco CMSMicrosoft Live Writer & UmbracoI was always vondering what is Content Channel tab in uses properties section used for. What ever I set in that tab for my admin user, nothing happendsThu, 10 Apr 2014 21:27:48 -04002014-04-10T21:27:48-04:003358https://dejanstojanovic.net/umbraco-cms/2014/april/i-lost-my-umbraco-admin-password-now-what/Umbraco CMSI lost my Umbraco admin password, now what?So you got a new requirement for the website you worked on ages ago. You try to login to Umbraco but your password is not correctThu, 10 Apr 2014 11:40:13 -04002014-04-10T11:40:13-04:002357https://dejanstojanovic.net/javascript/2014/april/jquery-cdn-with-fallback-strategy/JavaScriptJQuery CDN with fallback strategyContent Delivery Network or CDN is really usefull for loading JQuery and especially JQuery UI since it is pretty big script file. They are very ofter reliable, fast and since they can be used on other sites, they might be alrady cached in clients browser if he visited some website which uses the same CDN for JQuery or JQuery UI. There are a lot of CDN providers outhere, but two most common are for sure: Thu, 03 Apr 2014 23:54:42 -04002014-04-03T23:54:42-04:002340https://dejanstojanovic.net/javascript/2014/march/google-had-changed-their-policy-for-fetching-profile-image/JavaScriptGoogle had changed their policy for fetching profile imageGoogle have recently decided to change the way you can fetch profile image. Good old building of image URL is not supported anymore after Google has applied security policy. In good old, but unfortunately deprecated approach you only needed profile id to build a URL for fetching Google+ profile image like the following: Mon, 31 Mar 2014 16:49:49 -04002014-03-31T16:49:49-04:001297https://dejanstojanovic.net/umbraco-cms/2014/march/umbraco-backend-customization-handling-events/Umbraco CMSUmbraco backend customization - handling eventsIn Umbraco 6 new interface IApplicationHandler is introduced. By inheriting this interface in your class you can hook your custom methods to handle events which occur in Umbraco. The following two I use really often for controlling Umbraco behavior: Mon, 10 Mar 2014 08:41:47 -04002014-03-10T08:41:47-04:001287https://dejanstojanovic.net/umbraco-cms/2014/march/umbraco-backend-customization-custom-buttons/Umbraco CMSUmbraco backend customization - custom buttons This article is about extending Umbraco back-end with custom button to which you can attach your custom click handlers and force Umbraco back-end to work according to your needs. Wed, 05 Mar 2014 16:00:18 -05002014-03-05T16:00:18-05:001286https://dejanstojanovic.net/aspnet/2014/march/easy-data-visualization-with-google-graphs-api/.NETEasy data visualization with Google Graphs APIGoogle graph are really easy to use on website for the main reason that you do not need to maintain code and because it is free for use. Samples and documentation can be found at https://developers.google.com/chart/Wed, 05 Mar 2014 15:59:17 -05002014-03-05T15:59:17-05:001284https://dejanstojanovic.net/javascript/2014/march/dynamic-jquery-plugins-load/JavaScriptDynamic JQuery plugin files loadYou all probably had to deal with certain js files for JQuery plug-in. Usually developers add reference to a js file in Master page (if using WebForms) on layout view (is using MVC). This practice is not so bad, because you have references maintained in one file, but bad thing is that all js file are being load even if none of then are used on the particular pages. Wed, 05 Mar 2014 15:57:24 -05002014-03-05T15:57:24-05:001281https://dejanstojanovic.net/aspnet/2014/march/handling-ajax-request-in-webforms/.NETHandling ajax request in WebFormsIn case you want to add JQuery Ajax calls to your page, you would basically need to add one more page which will be invoked with Ajax call. In order to reduce number of physical pages you can reuse the same page, but make it act differently for normal GET/POST HTTP request and totally different for Ajax GET/POST HTTP requestWed, 05 Mar 2014 15:56:18 -05002014-03-05T15:56:18-05:001280https://dejanstojanovic.net/aspnet/2014/march/detect-ajax-request-in-c/.NETDetect ajax request in C#Sometime you need to determine whether your request is standard GET/POST request or Ajax POST/GET http request. This info is stored in request value isAjax or X-Requested-With. By checking these values of request you can easily determine whether http request is ajax or not. Wed, 05 Mar 2014 15:55:43 -05002014-03-05T15:55:43-05:001276https://dejanstojanovic.net/umbraco-cms/2014/march/extension-methods/Umbraco CMSExtending Umbraco API with extension methodsOften during writing partial view for page you need to read value from property which is content or media picker. In order to get integer value you need to cast value acquired with GetPropertyValue method which is object typeWed, 05 Mar 2014 10:24:25 -05002014-03-05T10:24:25-05:00