<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Mayur's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/mayurpatankar/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/mayurpatankar/feed.xml</link>
    <description />
    <lastBuildDate>Thu, 05 Apr 2018 07:45:57 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property</title>
      <link>https://docs.microsoft.com/archive/blogs/mayurpatankar/error-during-serialization-or-deserialization-using-the-json-javascriptserializer-the-length-of-the-string-exceeds-the-value-set-on-the-maxjsonlength-property</link>
      <pubDate>Thu, 05 Apr 2018 12:44:05 GMT</pubDate>
      <dc:creator><![CDATA[Mayur Patankar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mayurpatankar/?p=305</guid>
      <description><![CDATA[Recently , I came across an issue where my WebMethod call was failing with the below error message...]]></description>
      <content:encoded><![CDATA[Recently , I came across an issue where my WebMethod call was failing with the below error message .

&nbsp;

Error(s): {"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":"   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

&nbsp;

I was not sure what should be the length of maxJsonLength property so it will not fail in the future as well if in case my application is  pulling more data by using a WebMethod.  As we know in real world scenarios the data may increase in future and I may have to pull more records from the database which will crash my application and results in http 500 errors if i am exceeding the value set for maxJsonLength property.  I can not change this value every time based on amount of data I am pulling from the backend .  I need to have a safe value which I can specify and meets my future requirements too..

&nbsp;

Let’s try to understand What is <strong>maxJsonLength</strong> :

The maxJsonLength Gets or sets the maximum length that is accepted by the <a href="https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx">JavaScriptSerializer</a> object for JavaScript Object Notation (JSON) strings.

<strong>Syntax</strong> :

[ConfigurationPropertyAttribute("maxJsonLength", DefaultValue = 102400)]

public int MaxJsonLength { get; set; }

&nbsp;

<strong>Property</strong> <strong>Value</strong>

Type: <a href="https://msdn.microsoft.com/en-us/library/system.int32.aspx">System.Int32</a>

An integer that represents the maximum length for JSON strings. The default is 102400 characters.

&nbsp;

The value of the MaxJsonLength property applies only to the internal <a href="https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx">JavaScriptSerializer</a> instance that is used by the asynchronous communication layer to  invoke Web services methods.

Basically, the "internal" JavaScriptSerializer respects the value of maxJsonLength when called from a web method. Direct use of a JavaScriptSerializer (or use via an MVC action-method/Controller) does <strong>not</strong> respect the maxJsonLength property, at least not from the systemWebExtensions.scripting.webServices.jsonSerialization section which you define in the web.config file.

You will get the below error if you exceed the above default value(DefaultValue = 102400) while serializing the JSON object and your Json string is too big

Error(s): {"Message":"Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.","StackTrace":"   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)\r\n   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)\r\n   at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n   at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}

&nbsp;

Above error  “The length of the string exceeds the value set on the maxJsonLength property”  itself suggest that you have to increase the value for maxJsonLength property

&nbsp;

Now the  question in your mind would be how to define the “safe” number or how to find out the “safe” number for the value of the maxJsonLength property so we it will not fail in the future if the web service is accessing more data than the defined value(or default value) for the maxJsonLength  property.

The answer to the above question would be don’t pull huge data from the web service on a single request instead of that you can chunk the data and can access it , so it will not exceed the value you have set for the maxJsonLength.

Also , if you are pulling huge records on a single request it will definitely going to hamper the performance of your application . In order to get the Safe number for the maxJsonLenght you have to perform some rigorous testing on your application and determine the same. There is no such default value which will be same for any amount of data or records you are pulling for the database which is invoked from the Web Service method call.

If you are exceeding the default value for this property you have to update it in the web.config file as below :

&nbsp;

<span>&lt;configuration&gt;</span>

<span>   </span><span>&lt;system.web.extensions&gt;</span><span>       </span>

<span></span><span>  &lt;scripting&gt;</span><span>           </span>

<span></span><span>         &lt;webServices&gt;</span><span>    </span>

<span>            </span><span>&lt;jsonSerialization</span> <span>maxJsonLength</span><span>=</span><span>"...."</span><span>&gt;</span><span>          </span>

<span>           </span><span>&lt;/jsonSerialization&gt;</span><span>         </span>

<span>   </span><span>&lt;/webServices&gt;</span><span>     </span>

<span>   </span><span>&lt;/scripting&gt;</span><span>   </span>

<span></span><span>  &lt;/system.web.extensions&gt;</span>

<span>&lt;/configuration&gt;</span>

&nbsp;

Or else you also can set the maxJsonLength in your controller like this

JavaScriptSerializer jss = new JavaScriptSerializer();
jss.MaxJsonLength = Int32.MaxValue;

&nbsp;

Hope this helps!!!! J]]></content:encoded>
    </item>
    <item>
      <title>IIS Static compression : "The directory specified for caching compressed content  is invalid. Static compression is disabled" Warnings in event viewer(2264)</title>
      <link>https://docs.microsoft.com/archive/blogs/mayurpatankar/iis-static-compression-the-directory-specified-for-caching-compressed-content-is-invalid-static-compression-is-disabled-warnings-in-event-viewer2264</link>
      <pubDate>Fri, 16 Feb 2018 07:55:56 GMT</pubDate>
      <dc:creator><![CDATA[Mayur Patankar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mayurpatankar/?p=295</guid>
      <description><![CDATA[The &lt;httpCompression&gt; element specifies the HTTP compression settings for Internet Information...]]></description>
      <content:encoded><![CDATA[The <strong>&lt;</strong>httpCompression&gt; element specifies the HTTP compression settings for Internet Information Services (IIS) 7. HTTP compression can provide faster transmission times between IIS and client browsers that can accept compressed files.

More about <a href="https://docs.microsoft.com/en-us/iis/configuration/system.webserver/httpcompression/">httpcompression</a>

When a user requests for a page, the IIS worker process creates a folder specific to the application pool on the configured IIS Cache directory (One time i.e. under C:\inetpub\temp\IIS Temporary Compressed Files\appPoolName).

The folder is getting created but we are getting a warning on the Eventvwr for IIS-W3SVC-WP source.

“The directory specified for caching compressed content &lt;folder location&gt; is invalid. Static compression is disabled.

Log Name:     Application

Source:       Microsoft-Windows-IIS-W3SVC-WP

Date:         9/1/2017 3:07:58 PM

Event ID:     2264

Task Category: None

Level:         Warning

Keywords:     Classic

User:         N/A

Computer:

Description:

The directory specified for caching compressed content C:\inetpub\temp\IIS Temporary Compressed Files\appPoolName is invalid. Static compression is being disabled.

Event Xml:

&lt;Event xmlns="https://schemas.microsoft.com/win/2004/08/events/event"&gt;

&lt;System&gt;

&lt;Provider Name="Microsoft-Windows-IIS-W3SVC-WP" Guid="{670080D9-742A-4187-8D16-41143D1290BD}" EventSourceName="W3SVC-WP" /&gt;

&lt;EventID Qualifiers="32768"&gt;2264&lt;/EventID&gt;

&lt;Version&gt;0&lt;/Version&gt;

&lt;Level&gt;3&lt;/Level&gt;

&lt;Task&gt;0&lt;/Task&gt;

&lt;Opcode&gt;0&lt;/Opcode&gt;

&lt;Keywords&gt;0x80000000000000&lt;/Keywords&gt;

&lt;TimeCreated SystemTime="2017-09-01T22:07:58.000000000Z" /&gt;

&lt;EventRecordID&gt;1063103&lt;/EventRecordID&gt;

&lt;Correlation /&gt;

&lt;Execution ProcessID="0" ThreadID="0" /&gt;

&lt;Channel&gt;Application&lt;/Channel&gt;

&lt;Computer&gt; &lt;/Computer&gt;

&lt;Security /&gt;

&lt;/System&gt;

&lt;EventData&gt;

&lt;Data Name="Directory"&gt;C:\inetpub\temp\IIS Temporary Compressed Files\appPoolName&lt;/Data&gt;

&lt;Binary&gt;05000000&lt;/Binary&gt;

&lt;/EventData&gt;

&lt;/Event&gt;

Whenever we delete the subfolders under ' C:\inetpub\temp\IIS Temporary Compressed Files', the folder recreates with 'IUSRS' as the owner and we were not getting these warning logged again . But after sometime if we delete the app pool folder and  recycled the application pool the same warnings were getting logged on the event viewer for the first request .

Before troubleshooting this issue , make sure you have checked the below things :
<ul>
 	<li>Ensured that static compression is enabled on the IIS configuration</li>
 	<li>Provided the application pool service account/ IIS_IUSRS  required access on the IIS Cache directory</li>
 	<li>Do not change the Default location of this directory</li>
</ul>
In order to troubleshoot this issue further we ran the procmon and saw who is owning the compression folder
<ul>
 	<li>We found that the compression folder is being created (and owned by) <strong>IUSR</strong></li>
 	<li>The compression folder must be owned by the <strong>AppPool Identity</strong>.</li>
 	<li>IUSR is the default identity used by IIS when <strong>'Anonymous Authentication</strong>' is used</li>
</ul>
To resolve this issue we followed the below steps :

Right click 'Anonymous Authentication' in IIS -&gt; Set to 'AppPool Identity' -&gt; Delete compression folder -&gt; restart IIS website -&gt; When new compression folder is created it will be owned  by the AppPool identity and no Events 2264 will occur.

<strong>Note</strong>: The new owner will be 'Administrators' if the AppPool Identity is in the local administrators group.

&nbsp;

Hope this helps !!!  😊

&nbsp;]]></content:encoded>
    </item>
    <item>
      <title>SHA-256 Self Signed Certificate for Windows Server 2012 R2</title>
      <link>https://docs.microsoft.com/archive/blogs/mayurpatankar/sha-256-self-signed-certificate-for-windows-server-2012-r2</link>
      <pubDate>Fri, 01 Sep 2017 23:00:29 GMT</pubDate>
      <dc:creator><![CDATA[Mayur Patankar]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/mayurpatankar/?p=45</guid>
      <description><![CDATA[Recently, I came across this situation where one of my customer wants to use the Self Signed...]]></description>
      <content:encoded><![CDATA[Recently, I came across this situation where one of my customer wants to use the Self Signed Certificate to secure his intranet websites. But he wants to use the Self Signed Cert with the sha256 Signature Hash algorithm on Windows Server 2012 R2 as sha1 is retired.

By Default, in Windows 2012 R2 (IIS 8.5) if you generate the Self-Signed Certificate from the IIS Manager Console it will provide a Self-Signed Certificate with the <strong>Signature hash</strong> <strong>algorithm</strong> as <strong>sha1</strong> .

The SHA-1 hashing algorithm for the Microsoft Root Certificate Program is being decommissioned.

<a href="https://blogs.msdn.microsoft.com/spses/2014/10/21/sha-1-decommissioning/">https://blogs.msdn.microsoft.com/spses/2014/10/21/sha-1-decommissioning/</a>

&nbsp;

If you want your self-signed certificate should use the <strong>sha256 Signature hash algorithm</strong>, we have to generate the certificate from the mmc console

&nbsp;

You can follow below steps to create and use a Self-Signed Certificate with the <strong>Signature hash</strong> <strong>algorithm</strong> as <strong>sha256. </strong>

1.Open the mmc console &gt;&gt; go to Run &gt;&gt;&gt;type mmc &gt;&gt;&gt;OK

<img width="397" height="207" class="alignnone size-full wp-image-55" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/1..jpg" />

2. You will get the below Window (mmc console). Click on <strong>Add/Remove Snap-in</strong>

<img width="481" height="245" class="alignnone wp-image-65" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/2.jpg" />

3. Select <strong>Certificates </strong>&gt;&gt; <strong>Add </strong>

<img width="590" height="349" class="alignnone size-full wp-image-75" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/3.jpg" />

4. Select <strong>Computer Account </strong>and Click on <strong>Next</strong>

&nbsp;

<img width="678" height="371" class="alignnone wp-image-85" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/4.jpg" />

5.Click on <strong>Finish</strong>

<img width="651" height="406" class="alignnone size-full wp-image-95" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/5.jpg" />

6. The Certificates will be added in your snap-in

<img width="628" height="336" class="alignnone size-full wp-image-105" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/6.jpg" />

&nbsp;

7. Expand <strong>Certificates</strong> (Local Computer) &gt;&gt;&gt;<strong>Personal</strong> &gt;&gt;&gt;&gt;&gt;<strong>Certificates</strong> &gt;&gt;&gt;&gt;&gt;<strong>All Tasks</strong>&gt;&gt;&gt;&gt;&gt;<strong>Advanced Operations</strong>&gt;&gt;&gt;&gt;&gt;<strong>Create Custom Request</strong>

&nbsp;

<img width="796" height="377" class="alignnone size-full wp-image-115" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/7.jpg" />

8. Click on <strong>Next</strong>

&nbsp;

<img width="649" height="405" class="alignnone size-full wp-image-116" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/8.jpg" />

&nbsp;

9.Select <strong>Proceed without enrollment policy</strong>&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Next</strong>

<img width="870" height="481" class="alignnone size-full wp-image-125" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/9.jpg" />

&nbsp;

10. Click on <b><strong>Next</strong></b>

&nbsp;

<img width="581" height="331" class="alignnone size-full wp-image-135" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/10.jpg" />

11.Click on <strong>Details</strong> &gt;&gt;&gt;&gt;&gt;<strong>Properties</strong> &gt;&gt;&gt;&gt;<strong>Next</strong>

&nbsp;

<img width="727" height="359" class="alignnone size-full wp-image-145" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/11.jpg" />

&nbsp;

12.Add the Friendly for your certificate as per your choice

&nbsp;

<img width="720" height="401" class="alignnone size-full wp-image-165" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/12.jpg" />

&nbsp;

13<b>. </b>Click on <b><strong>Subject</strong> &gt;&gt;&gt;&gt;&gt;&gt;<strong>Subject Name</strong> &gt;&gt;&gt;&gt;<strong>Type</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Select Common Name</strong> (</b>Common Name should be your host name with which you are browsing your site<b>) &gt;&gt;&gt;<strong>Add  </strong></b><strong>Alternative Name</strong> &gt;&gt;&gt;&gt;<strong>Type</strong> &gt;&gt;&gt;&gt;<strong>DNS</strong>&gt;&gt;&gt;&gt;&gt;<strong>Add your DNS</strong> (domain name here)&gt;&gt;&gt;&gt;<strong>Add</strong>

&nbsp;

<img width="701" height="382" class="alignnone size-full wp-image-175" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/13.jpg" />

&nbsp;

14. Click on <strong>Extensions tab</strong>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Extended Key Usage</strong> (application policies)

&nbsp;

<img width="740" height="374" class="alignnone size-full wp-image-185" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/14.jpg" />

&nbsp;

15.Click <strong>Basic Constraints</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Select Enable this extension</strong>

<img width="719" height="387" class="alignnone size-full wp-image-195" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/15.jpg" />

&nbsp;

16. Go to <strong>Private Key tab</strong>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Key Options</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;Select <strong>Make private key exportable</strong>

<img width="873" height="445" class="alignnone size-full wp-image-205" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/16.jpg" />

&nbsp;

17. Go to <strong>Private Key tab</strong>&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Select Hash Algorithm</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Hash Algorithm</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>sha256(Here you will select the Signature hash algorithm )</strong>

&nbsp;

<img width="939" height="435" class="alignnone size-full wp-image-215" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/17.jpg" />

18. Click on <strong>Apply</strong> &gt;&gt;&gt;<strong>Ok</strong>

&nbsp;

<img width="726" height="374" class="alignnone size-full wp-image-225" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/18.jpg" />

&nbsp;

19. Click <strong>Next</strong>

&nbsp;

<img width="821" height="424" class="alignnone size-full wp-image-235" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/19.jpg" />

20. Click on Browse and give the certificate with <strong>CertName.cer</strong> and click on <strong>Finish</strong>

&nbsp;

<img width="708" height="364" class="alignnone size-full wp-image-236" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/20.jpg" />

&nbsp;

21. Click on <strong>Certificate Enrollment Requests</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;Right click on <strong>Certificates</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>All Tasks</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Import</strong>

<img width="787" height="372" class="alignnone size-full wp-image-246" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/21.jpg" />

&nbsp;

22. Click on <strong>Next</strong>

<img width="783" height="402" class="alignnone size-full wp-image-255" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/22.jpg" />

&nbsp;

23. Specify the file name and the location

&nbsp;

<img width="752" height="397" class="alignnone size-full wp-image-265" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/23.jpg" />

&nbsp;

24. Click on <strong>Next</strong>

&nbsp;

<img width="804" height="418" class="alignnone size-full wp-image-266" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/24.jpg" />

25. Click on <strong>Finish</strong>

<img width="645" height="345" class="alignnone size-full wp-image-275" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/25.jpg" />

26. Click on <strong>OK</strong>

<img width="660" height="332" class="alignnone size-full wp-image-277" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/26.jpg" />

&nbsp;

27. You will see your certificate here under <strong>Certificate Enrollment Requests</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt; <strong>Certificates</strong>

&nbsp;

<img width="591" height="285" class="alignnone size-full wp-image-285" alt="" src="https://msdnshared.blob.core.windows.net/media/2017/09/27.jpg" />

&nbsp;

28. Double click on the certificate &gt;&gt;go to <strong>Details</strong> &gt;&gt;&gt;&gt;Click on <strong>Copy to File</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Next</strong> &gt;&gt;&gt;&gt;&gt;&gt;&gt;&gt;<strong>Select the Format you want to use</strong> &gt;&gt;&gt;give the file name and the import it to the desktop&gt;&gt;&gt;&gt;&gt;&gt;<strong>Finish</strong>

&nbsp;

29. Import the certificate in <strong>Personal Store</strong>

&nbsp;

Now, check the Certificate go to Details tab check for the Signature hash algorithm &gt;&gt;&gt;&gt;it will be <strong>sha256</strong>

<strong> </strong>

Import the Certificate to the IIS and add the http binding for the site select the cert.

&nbsp;

You have to add this certificate on every client machine from where you want to access the site.

On the Client Machines:

Run &gt;&gt;&gt;&gt;&gt;mmc &gt;&gt;&gt;&gt;&gt;file&gt;&gt;&gt;&gt;&gt;&gt;Add/Remove Snap in &gt;&gt;&gt; add the Certificates &gt;&gt;&gt;&gt;&gt;select Computer Account &gt;&gt;&gt;&gt;import the certificate under Trusted Root Certification Authorities

&nbsp;

Hope this helps !!!!!..]]></content:encoded>
    </item>
  </channel>
</rss>