A potentially dangerous Request.Path value was detected from the client

I have a Odata service implementation and started getting errors where one of parameters in query has ‘:’.

Solution:

<system.web>
    <httpRuntime requestValidationMode="2.0" requestPathInvalidCharacters=""/>
<pages validateRequest="false">
Share

IOC- MEF,UNITY reading of a day

Couple of good readings regarding MEF usage.

Share

Reseting local Windows Azure storage

I run few days into a problem when I was not able to delete local development storage tables using Windows Azure API and system was throwing me exceptions. The reason of these exceptions I guess was the fact that table were very big.

In basic scenarios resetting can be archived with Storage emulator UI. 

 

clip_image002

 

I tried this but my machine became unresponsive because due too DSService.exe and sql service.

clip_image002[5]

Killing services left azure tables as they were before.

It turned out that you can also use %Azure SDK%\bin\devstore\dsinit.exe  /forceCreate command , which worked perfectly for me.

Share

LINQ Contains operation is not supported by Azure Table API

 

Unfortunately Azure API not supporting Contains LINQ expressions .

 

Contains Syntax:

LINQ

public static Product[] GetProducts(Guid[] prodIDs)

{

   return (from p in GetProducts()

where prodIDs.Contains(p.ProductID)

select p).ToArray<Product>();

}

TSQL expression  – WHERE [t0].[ProductID] IN (@p0, @p1)’,

LINQ contains syntax example has been taken from http://weblogs.asp.net/dwahlin/archive/2008/05/09/using-linq-to-perform-quot-where-in-value1-value2-quot-queries.aspx

Share

Improving performance for Windows Azure tables

Original article NET and ADO.NET Data Service Performance Tips for Windows Azure Tables.

 

Summary:

Default .NET HTTP connections is set to 2

Config file:
  <system.net>
    <connectionManagement>
      <add address = "*" maxconnection = "48" />
    </connectionManagement>
  </system.net> 

In code:
ServicePointManager.DefaultConnectionLimit = 48; 

Turn off 100-continue (saves 1 roundtrip)

    Code:
    ServicePointManager.Expect100Continue = false; // or on service point if only a particular service needs to be disabled.  
    
    Config file:
    <system.net> 
    
        <settings> 
    
          <servicePointManager expect100Continue="false" /> 
    
        </settings> 
    
    </system.net> 

To improve performance of ADO.NET Data Service deserialization name CLR Enity and table identically and use ResolveType on the

public void Query(DataServiceContext context)
                {
                     // set the ResolveType to a method that will return the appropriate type to creat

                     context.ResolveType = this.ResolveEntityType;   

                }
 public Type ResolveEntityType(string name)
 {  

                      // if the context handles just one type, you can return it without checking the   
                      // value of "name".  Otherwise, check for the name and return the appropriate  
                      // type (maybe a map of Dictionary<string, Type> will be useful) 

                      Type type  = typeof(Customer);
                      return type;
}  

Turn entity tracking off for query results that are not going to be modified.

    context.MergeOption = MergeOption.NoTracking;

    Use unconditional updates/deletes

    context.AttachTo("TableName", entity, "*");
    context.UpdateObject(entity); 

 Turning off Nagle may help Inserts/Updates

Code:
ServicePointManager.UseNagleAlgorithm = false; 

Config file: 

<system.net>
    <settings>
      <servicePointManager expect100Continue="false" useNagleAlgorithm="false"/>
    </settings>
</system.net> 
Share

StorageClient.StorageClientException: The specified blob already exists

Got interesting exception today while trying to upload multiple file blobs to Azure container.

 

private void UploadFileToBlob(string url, Asset asset,string filepath,string filename)
       {
           var container = new CloudBlobContainer(url);

           //Get a reference to a blob, which may or may not exist.
           CloudBlob blob = container.GetBlobReference(filename);
           blob.DeleteIfExists();
           //Upload content to the blob, which will create the blob if it does not already exist.
           blob.UploadFile(filepath);
       }

When I am executing UploadFileToBlob for one file it is working. On different multiple files it is throwing exception “StorageClient.StorageClientException: The specified blob already exists”.

Did some research and found out that this problem associated with multithreading in local dev storage:



This is a known issue with development storage. This happens when there are multiple threads launched to upload the blocks (which constitute the blob). Basically what is happening is that development storage makes use of SQL Server as the data store. Now first thing it does is makes an entry into the table which stores blob information. If there are multiple threads working then all of these threads will try to perform the same operation. After the first thread succeeds, the subsequent threads will result in this exception being raised.

http://stackoverflow.com/questions/4897826/azure-storage-error-the-specified-blob-already-exists-but-it-doesn’t.

Kind of weird, will try to investigate more to see how to resolve this issue and if size of file is really matter. Please let me know if you found any workarounds.

Share

Deploying MVC dependencies to Azure

If you creating web application to be deployed to Windows Azure, you probably noticed that deployment and azure instance initialization may take a while. Any missing reference or break will cause you time and lost productivity.

Few days ago I spent couple of hours trying to include all mvc references one by one making sure that application app has minimum set of required assemblies.

Phil hack published an article http://haacked.com/archive/2011/05/25/bin-deploying-asp-net-mvc-3.aspx regarding how to include MVC,Razor dependencies into your deployment.

By default Azure instance will not have required packages installed. So you need to make sure that all files will be located in your bin folder.

“If your server doesn’t have ASP.NET MVC 3 installed, you’ll need to make sure the following set of assemblies are deployed in the bin folder of your web application:

  • Microsoft.Web.Infrastructure.dll
  • System.Web.Helpers.dll
  • System.Web.Mvc.dll
  • System.Web.Razor.dll
  • System.Web.WebPages.Deployment.dll
  • System.Web.WebPages.dll
  • System.Web.WebPages.Razor.dll

Simply right click on your project to add deployable dependencies.

 add-deployable-assemblies

For other GAC assemblies which are not part of .net 4.0 framework make sure to set Copy Local flag to true:

image

Share

ODATA WCF Data Services Friendly URLS using Routing

When you creating your first OData WCF Data service common tasks is to give a friendly URL instead of using filename.svc as entry point.You can archive it with URL routing feature in ASP.NET MVC.Just modify your Global.asax.cs route registration block to include following lines.

public static void RegisterRoutes(RouteCollection routes)
       {
           routes.Clear();
           var factory = new DataServiceHostFactory();
           RouteTable.Routes.Add(
               new ServiceRoute("API", factory, typeof (TestOdataService)));

It tells system to associate data service factory handler with a given URL.

Share

iPad User agent string

Here it is:
Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.10
You can test how you page looks like in Apple IPad by using safari browser and changing it from Safari to IPad.
Google analytics also providing report to see what mobile devices your visitors used.

Share

WordPress Error: Jquery is not defined

After installing WordPress site and downloading plugins i noticed that half of admin functionality is not working.

I tried to search for solutions and did some debugging and here what i found.

Solution 1 (worked for me):
1. In wp-config.php insert define(‘CONCATENATE_SCRIPTS’, false ); at the beginning of file.Once you will add this your scripts requests will not be merged together, so you will be able to do investigation
2. Open Firebug in FF or developer toolbar in IE (F12) or Tools->Developer Tools in Chrome to see outgoing requests
3.Find request wp-includes/js/jqure.js
4. In my case it was returning 403 error – Forbidden
5. Change permissions to files using chmod command :chmod -R 777 /var/www/wp-includes/js

Solution 2(reported to be working for various users in different posts):
You have missing files in /var/www/wp-includes/js
1. Download wp source code from wp site and unzip them
2. Upload wp-includes/js folder to your site wp-includes/js folder via ftp

Solution 3:
1.Disable all plugins
2.Make sure that problemis fixed and start enabling plugins one at a time to isolate corrupted

Share