Unrecognized attribute “targetFramework” when deploying asp.net 4.0

Ok you start developement with .net framework 4.0 and possibly try to deploy your site to iis first time and getting this error :Unrecognized attribute “targetFramework” when deploying asp.net 4.0 Because you did not configure your iis run with .net framework 4.0.

For do it you have to change your path to


that execute command of

aspnet_regiis.exe -iru

if you already do this and getting this error you should better to check your site application pool for correct .NET framework version chosen.

Application Pools->Select yours -> Basic Settings -> And change .NET framework version

Thats it folks.


Detect asyncronous postback in asp.net

You can detect asyncronous postback with ScriptManager.IsInAsyncPostBack property.

protected void Page_Load(object sender, EventArgs e) {       if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack)       {            //Do your job here.       } } Happy Tips..

How to set host header II7 for SSL binding 443

Open the command prompt by clicking the start menu and typing “cmd” and hitting enter.

Navigate to C:\Windows\System32\Inetsrv\ by typing “cd C:\Windows\System32\Inetsrv\” on the command line.

Here is the syntax:

appcmd set site /site.name:”<YourIISSiteName>” /+bindings.[protocol=’https’,bindingInformation=’*:443:<YourhostHeaderValue>‘]

An Example:

appcmd set site /site.name:”DemoPortal” /+bindings.[protocol=’https’,bindingInformation=’*:443:demo.portalcompany.com‘]


c# getting day name for specific culture

Here is a small example for getting day name of a date by specific culture:


DateTime startDate = DateTime.Now;

DateTime endDate = DateTime.Now.AddDays(2);


CultureInfo c = new CultureInfo("tr-TR");

string startDayName = c.DateTimeFormat.DayNames[(int)startDate.DayOfWeek];

string endDayName = c.DateTimeFormat.DayNames[(int)endDate.DayOfWeek];



Happy Tips.

Sharepoint 2010 with Microsoft Distributed Cache (Velocity)

Microsoft Distributed Cache “Velocity”  provides a highly scalable in-memory application cache for all kinds of data. By using cache, your application performance can improve significantly by avoiding unnecessary calls to the data source. You know for sharepoint farms caching and session management is one of challenging issue. Sharepoint farms have many servers as application servers, web front end (WFE) servers etc. And using Network  load balancing (NLB) services for efficiency. By default your caches are server specfic and you can not  use cached data by other WFE  servers except which one of them has cached the data.

Velocity offers a custom state provider for your ASP.NET Web applications. This lets Web applications spread  objects across the cache cluster, providing scalability. Due to the nature of “Velocity,” objects that you put in  must be serializable.

Alternatively you can use SQL Server for SessionState but this solution has some disadvantages.For example performance and high availability are the key points.

  • InProc – Fastest, but the more session data, the more memory is consumed on the web server, and that can affect performance.
  • StateServer – When storing data of basic types (e.g. string, integer, etc), in one test environment it’s 15% slower than InProc. However, the cost of serialization/deserialization can affect performance if you’re storing lots of objects. You have to do performance testing for your own scenario.
  • SQLServer – When storing data of basic types (e.g. string, integer, etc), in one test environment it’s 25% slower than InProc. Same warning about serialization as in StateServer.

You can also use 3rd party distributed caches that Memcached , ScaleOut, NCache,SharedCache some options .

Some advantages of Velocity:

  • Scalebility: Velocity provides a cache cluster with multiple hosts and spread cache data between hosts.You can add more servers to the cache cluster.
  • High Availablity:The high availability feature in Microsoft project code named “Velocity” supports continuous availability of your cached data by storing copies of that data on separate cache hosts. When you have high availability enabled on a multi-server cluster, your application can still retrieve its cached data if a cache server fails
  • Cache Notifications:Microsoft project code named “Velocity” offers cache notifications that allow your applications to receive asynchronous notifications when a variety of cache operations occur on the cache cluster. Cache notifications also provide automatic invalidation of locally cached objects
  • Concurrency Models :To help your application deal with concurrency issues, “Velocity” supports optimistic and pessimistic concurrency models
  • SessionState Provider: you can share sessions across multiple sites. You can now host your application in multiple sites and have users visit one location to another without losing their sessions.

About Performance of Velocity :
MSDN Magazine Article about Velocity says “Simply put, if accessing the cache is not faster than accessing your database, there is no need to have it. Having said that, what should you expect in terms of performance from a good distributed cache?

The first thing to remember is that a distributed cache is usually OutProc or remote, so access time will never be as fast as that of a stand-alone InProc cache (for example, ASP.NET Cache). In an InProc stand-alone cache, you can probably read 150,000 to 200,000 items per second (1KB object size). With an OutProc or a remote cache, this number drops significantly. In terms of performance, you should expect about 20,000 to 30,000 reads per second (1KB object size) as the throughput of an individual cache server (from all clients hitting on it). You can achieve some of this InProc performance by using a client cache (in InProc mode), but that is only for read operations and not for write operations. You sacrifice some performance in order to gain scalability, but the slower performance is still much faster than database access.”
Using Velocity With Sharepoint:
I assume that you already setup and configure your distribute cache hosts and clusters up and running.

1)Copy Client DLL’s to your bin directory
  • CacheBaseLibrary.dll
  • ClientLibrary.dll
  • FabricCommon.dll
  • CASBase.dll
Important  : In my case first i try to register dll to GAC but it occurs some dependency problems you may use copy bin options.

2)Web.Config configurations:
into configSection tag:
< section name=”dataCacheClient” type=”Microsoft.Data.Caching.DataCacheClientSection, CacheBaseLibrary, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91″ allowLocation=”true” allowDefinition=”Everywhere” / >
into Configuration tag: (For example after < / configSections > tag)
< dataCacheClient deployment=”simple” >
< localCache isEnabled=”true” sync=”TTLBased” ttlValue=”300″  / >
<host name=”bugrapostaci” cacheHostName=”DistributedCacheService” cachePort=”22233″  / >

Into SafeControls tag:

<SafeControl Assembly=”CacheBaseLibrary, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91″ Namespace=”Microsoft.Data.Caching” TypeName=”*” Safe=”True” SafeAgainstScript=”False”  / >

<SafeControl Assembly=”ClientLibrary, Version=, Culture=neutral, PublicKeyToken=89845dcd8080cc91″ Namespace=”Microsoft.Data.Caching” TypeName=”*” Safe=”True” SafeAgainstScript=”False”  / >

My Code for sample webpart:

using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using Microsoft.Data.Caching;


namespace DistributedCacheTest.DistributedCacheClient


public partial class DistributedCacheClientUserControl : UserControl


protected void Page_Load(object sender, EventArgs e)


DataCacheServerEndpoint[] servers = new DataCacheServerEndpoint[1];


////specify cache host(s)

servers[0] = new DataCacheServerEndpoint(“BUGRAPOSTACI”,

22233, “DistributedCacheService”);


//specify cache client configuration

DataCacheFactory mycacheFactory

= new DataCacheFactory(servers, true, false);


//get cache client for default cache

DataCache dCache = mycacheFactory.GetDefaultCache();

string cacheContent = dCache.Get(“TestKey”) as string;

Response.Write(“VALUE = “ + cacheContent);





Important :When installing Velocity If your religional settings is different from “en-xx” some language specific characters can be problematic .In my case because of turkish char “i” and “ı” i got exception “url not found” and unable to start cache cluster.  I solved this problem with change my religional settings of computer  to english and reinstalled velocity .

Important:Velocity client dll’s needs Custom Access Policy configuration when using bin directory copy-paste deployment. I suggest that you should change your “trust” option in your web.config to “Full” instead of using default value  of “WSS_Minimal”.
<trust level=”Full”  />

Download Microsoft Distributed Cache:

Other Sources:


End of article .)


when CacheItemRemovedCallback is raised HttpContext.Current is null

CacheItemRemovedCallback shows users the value assigned to an item in the cache and then notifies them when the item is removed from the cache. It creates a RemovedCallback method, which uses the signature of the CacheItemRemovedCallback delegate, to notify users when the cache item is removed and uses theCacheItemRemovedReason enumeration to tell them why it was removed.But when you try to use cache with HttpContext.Current it encounter an object not set reference error.

Here is the solution.

Use :HttpRuntime.Cache instead of HttpContext.Current.Cache object


 public static void DropUser(string key, object value, CacheItemRemovedReason reason)
            List<string> OnlineUserAccounts = null;
            if (HttpRuntime.Cache[CACHE_KEY] != null)
                OnlineUserAccounts = (List<string>)HttpRuntime.Cache[CACHE_KEY];
                if (OnlineUserAccounts.Contains(key))
                    HttpRuntime.Cache[CACHE_KEY] = OnlineUserAccounts;
Happy Codding.

Restriction Module : secure your asp.net application

RestrictionModue makes life easier that secure your asp.net or sharepoint site content, pages or documents when authorization restrictions or standart restrictions are not enough. Its developed in c# 3.5.

What is Restriction Module

Restriction module is an open source project based on a httpmodule that alternatively provide security to your web applications. You can define rules that protect your pages,contents or documents. Use more flexible restrictions using power of regular expression than forms authentication web.config options.You can change security settings in runtime. And no need to recycle application or no extra down time .

Configuration of  Restriction Module

  • Add Module Definition:

Add this key below to your web.config file: configuration/system.web/httpModules

<add name=”RestrictionModule” type=”RestrictionModuleApp.RestrictionModule, RestrictionModuleApp,Version=, Culture=neutral, PublicKeyToken=be23a05ec1781ff6″  />

  • Add switch key:

Add belowed key to configuration/appSettings
<add key=”RestrictionModuleActive” value=”On” />

İf value is on means module is active off means inactive.

  • Copy  Restriction.xml to your application path

Restriction.xml file definitions

You should define restrictions rules in restriction xml . Here is an example .

<?xml version="1.0" encoding="utf-8"?>
<RestrictionRules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <RestrictionRule Enabled="false" Action="Deny" Mode="RequestURL" ContinueRuleList="false">
      <Expression Type="Contains" CaseSensitive="false">/Pages/Forms/</Expression>
      <Expression Type="Contains" CaseSensitive="false">/_layouts/</Expression>

Restriction Rule:

You can define a restriction rule between <RestrictionRule></RestrictionRule> tags.

Restriction Rule Parameters:

  • Enabled: Boolean. Makes this rule active or inactive
  • Action: Gets two parameters  “Allow” and “Deny”. Default is “Deny”.If you choose “allow” by default  all request redirect to  url which is defined redirectURL parameter except selected user scope (if Audiences parameter is empty means all user is selected . All requests are not redirected) . Otherwise you choose “Deny”  by default all request continue with its normal destination except selected users redirect to  url which is defined RedirectURL parameter
  • Mode: Defines an envoriment variable in httpcontext for restriction
    • RequestURL: Restrict request with using raw url of request.
    • RequestUserHostName: Restrict request by UserHostName
    • RequestContentType: Restrict request by Content Type.
    • RequestUserHostAddress: Restrict request by UserHostAddress
  • ContinueRuleList: Boolean. By default If one rule match with expression and not match any criteria the other rules will not execute. If you set this parameter “true” the other rules will be executed what if an expression matched for one rule.  This feature should be used two different rule with same expression but modes are not equal.

For example:

Rule1: deny select url contains “/pages/” for A and B user. -> Redirect to access denied page

Rule2: deny select ip startwith “192.168” for A and C user  -> Redirect to access denied page

İf user “C” make a request a pagewith url contains “/pages/” rule expression match but identity not .By default expression match is enough and the other rules not executed.For execute rule2 you should set this parameter true in rule1.


You can define one or more expression in a rule. There is no expression continue list option.if one expression is match with the pattern or criteria,  the others not execute.Also there is no relation between expressions.

  • Type : Defines an operation on envoriment variable .Available operations
    • Contains : Search given parameter with in variable
    • StartWith : Search given parameter  at start of variable
    • EndWith : Search given parameter at end of variable
    • RegularExpression:Search given patterns and user parameter as variable.
    • CaseSensitive: Boolean . Define case sensitivity feature except Regular Expression.Default is false. İf you want use case sensitivity in regular expression,you have to write in pattern.


If any rule’s expression match with the criteria request will redirect to this url. Usually this url is Access Denied page or login page url.


Access list for a rule. If its empty means all users.If you want to define more than one user you have to seperate identities  by comma “,”.



Exampe Restrictions Rules

Other users will restricted.

<?xml version="1.0" encoding="utf-8"?>
<RestrictionRules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <RestrictionRule Enabled="false" Action="Allow" Mode="RequestURL" ContinueRuleList="false">
      <Expression Type="StartWith" CaseSensitive="false">https://blog.bugrapostaci.com/admin</Expression>
    <RedirectURL>http://blog.bugrapostaci.com /ErrorPages/401.aspx
  • Example 2 : Deny “Guest” user to reach pages url which contains /Pages/Forms and /Pages/Admin/
<?xml version="1.0" encoding="utf-8"?>
<RestrictionRules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <RestrictionRule Enabled="false" Action="Deny" Mode="RequestURL" ContinueRuleList="false">
      <Expression Type="Contains" CaseSensitive="false">/Pages/Forms/</Expression>
      <Expression Type="Contains" CaseSensitive="false">/Pages/Admin/</Expression>
    <RedirectURL>http://blog.bugrapostaci.com /ErrorPages/401.aspx

  • Example 3 : Deny all users which ip address start with “192.168.10”
<?xml version="1.0" encoding="utf-8"?>
<RestrictionRules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <RestrictionRule Enabled="false" Action="Deny" Mode="RequestUserHostAddress" ContinueRuleList="false">
      <Expression Type="StartWith" CaseSensitive="false">192.168.10</Expression>
    <Audiences> </Audiences>
  • Example 4 : Multiple Rules
<?xml version="1.0" encoding="utf-8"?>
<RestrictionRules xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">

  <RestrictionRule Enabled="false" Action="Deny" Mode="RequestURL" ContinueRuleList="true">
      <Expression Type="Contains" CaseSensitive="false">/Pages/Forms/</Expression>
      <Expression Type="Contains" CaseSensitive="false">/Pages/Admin/</Expression>
    <RedirectURL>http://blog.bugrapostaci.com /ErrorPages/401.aspx
<RestrictionRule Enabled="false" Action="Deny" Mode="RequestUserHostAddress" ContinueRuleList="false">
      <Expression Type="StartWith" CaseSensitive="false">192.168.10</Expression>

You can visit project page:


You can download release version :


And here is the user manuel


Happy codding.