Document {Blob Path} Has Unsupported Content Content Type in Azure Search Indexer

If you have done some development with Azure Search and Azure Blob Storage, then you may also have the similar experience. For me, I have an Azure Search Indexer, and it is pointing to Azure Blob Storage. The Azure Search Indexer is reporting “Document ‘{blob Path}’ has unsupported content type ‘unsupported'” after the indexer runs.

From the Microsoft Docs on Indexing Documents in Azure Blob Storage with Azure Search , it states that the supported document formats are,

  • PDF
  • Microsoft Office formats: DOCX/DOC, XLSX/XLS, PPTX/PPT, MSG (Outlook emails)
  • HTML
  • XML
  • ZIP
  • EML
  • RTF
  • Plain text files (see also Indexing plain text)
  • JSON (see Indexing JSON blobs)
  • CSV (see Indexing CSV blobs preview feature)

And the above error message is stated when the format is txt, msg, and html. I have asked around and someone from Microsoft ask me to test by starting very simple content until I hit into error. But I found out it fails except blank content in the file.

After few months on the trying, testing, and back and forth the comments, my boss give me a deadline as we cannot wait to launch the application. So in the end, the only way to make it works, is turn off the “FailOnUnsupportedContentType” using the REST API.

"parameters": { 
    "configuration": { 
       "indexedFileNameExtensions" : ".html,.txt,.pdf,.docx",
       "excludedFileNameExtensions": ".bmp,.dib,.png,.jpeg,.jpg,.jpe,.jfif,.gif,.tif,.tiff,.ico",
      "failOnUnsupportedContentType" : false
     }
 },

After that, now my indexer is running good, all new uploaded blob can get all data I want into Azure Search Index. Hope this could help you. And if you know the possible reason why these formats (txt, msg, html) are listed as supported but it keeps generating error as unsupported, please leave me message. I will also come to this topic if I found any updates.

Configure CORS in Azure

In my last post, I showed how to enable CORS in ASP.NET WebAPI. I then found out that I have another issue when hosting it in Azure. Azure has a great supporting on the CORS. You could watch a video about how great it is, here

First, I would like to show you how to enable CORS in Azure.
1) Go to Azure portal, click into the App Service of your WebAPI.
2) Then under API Tag, click CORS.
3) Enter “*” or any specified website that you would like to allow CORS.

DONE! That is easy, isn’t it.

But then if you start running your mobile or website, and fire any jQuery to the WebAPI, you will find this error,

“SEC7128: Multiple Access-Control-Allow-Origin headers are not allowed for CORS response.”

 

If you check in Fiddler, you will find this,

This is because that Azure has enable the CORS and your app also enabled it. So it has more than one entries on “Access-Control-Allow-Origin” which the preflight request does not allow it. Now we could make some changes to the web.config under Azure,

  1. Go into Azure portal, Under “development Tools” tag and click “Advanced Tools”. In the Detail panel, click “GO”.
  2. A new browser will pop up and it is showing on the Kudu page.
  3. Now you have to click “Debug console” –> “CMD”
  4. An Azure command prompt shows with a window in upper area like a windows explorer which allowing us to browse into different directory in Azure.
  5. Now browse into “site” –> “wwwroot”, you could found your web.config here.
  6. In the left hand side, you could then click on the “Edit” (a pencil icon) to edit the web.config of the WebAPI in browser.
  7. Now you could comment both of the “Access-Control-Allow-Origin” and “Access-control-Allow-Methods”. And then click Save button in the upper area to save your changes.

DONE again. now your website will have only one entry of the “Access-control-Allow-Origin” and “Access-Control-Allow-Methods” and your client app now can fire any jQuery to the WebAPI without any error.

P.S., Azure has improved the handling of the CORS on the “OPTION” issue that I found from the last post.

You could also check here to learn more about the Kudu

 

 

Supporting HTTP method ‘OPTIONS’ and CORS for Web API

Enable CORS

If you read the Web API tutorials from docs.microsoft.com, all of them are teaching you to create the server app (Web API) and the client app (ASp.NET MVC) in the same solution. In fact, we usually separate the server and client application into separate applications. You will then find out the client application cannot call any Web API method in server application. It is because of the CORS.

Cross Origin Resource Sharing (CORS) is a W3C standard that allows a server to relax the same-origin policy. Using CORS, a server can explicitly allow some cross-origin requests while rejecting others. CORS is safer and more flexible than earlier techniques such as JSONP. This tutorial shows how to enable CORS in your Web API application.

If you application is ASP.NET Web API 2, now you could do the following to enable CORS

  1. install Microsoft.AspNet.WebApi.Cors from Nuget

  2. Open file App_Start/WebApiConfig.cs. In Register method, add this code config.EnableCors();

  3. You can then adding “[EnableCors(origins: “https://localhost:8080”, headers: “*”, methods: “*”)]” to any method that you want to enable CORS

  4. You could also add the following into Web.config, so that CORS will be enabled to all methods

    <httpProtocol>
    <customHeaders>
    <!-- Allow Web API to be called from a different domain. -->
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Methods" value="*" />
    </customHeaders>
    </httpProtocol>

Now your server application Web API is ready to serve other client applications’ calling. You could read more here, Enabling Cross-Origin Requests in ASP.NET Web API 2

Support HTTP Method ‘OPTIONS’

If your client code is calling the Web API in javaScript, the execution will be fine on Http GET and POST. If your javaScript is Http PUT or DELETE, you will find this error,

The requested resource does not support http method ‘OPTIONS’.

 

Most of the browser will send a Preflight Request before it sends the actual request. One of the conditions to skip the Preflight Request is “The request method is GET, HEAD, or POST”. if you search to solve it, you will find that most of the result are stating that you could add and remove some handler in web.config could help.

Someone reported that it really solve the problem, but it does not work in my environment. I then also found out that there is another work around and it really works for me. (This is also the main reason why I blog it down and share with you now.) We now adding some handling to the HTTP OPTIONS verb in BeginRequest method.

protected void Application_BeginRequest(object sender, EventArgs e)
{
if (HttpContext.Current.Request.HttpMethod == "OPTIONS")
{
//These headers are handling the "pre-flight" OPTIONS call sent by the browser
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE");
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept");
HttpContext.Current.Response.AddHeader("Access-Control-Allow‌​-Credentials", "true");
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000");
HttpContext.Current.Response.End();
}
}

 

BINGO!

If you check in Fiddler, now the Server Application Web API is accepting the OPTIONS method and response to your client app that the is now ready to receive your PUT/DELETE call.

[Solved] “Win10 Mail and Calendar Crash”

I am running a new PC and installed win10 1703. I tried to open Mail app and found out that it crashed and closed after opening it for 2-3 seconds. I tried to search and found many blogs that showing me to uninstall and reinstall it back from App Store. I also found some posts showing me to grant FULL permission to “Users” on AppData in my user profile. But none of them can really solve the problem and Mail app is still crashing.

Until today, I open event viewer and found a lot of errors on ESENT with event ID 455.

svchost (8300) Unistore: Error -1023 (0xfffffc01) occurred while opening logfile C:\Users\kenlin\AppData\Local\Comms\UnistoreDB\USS.jtx.

I found out that UnistoreDB is a folder for Mail and Calendar. so I tried to browse into this folder and found out that the folder “Comms” and its sub-folder “UnistoreDB” are missing. I then create it by my own. Bingo! Mail and Calendar is working now! Problem Solved.

Hope this blog could also help you to resolve the Mail app crash.

 

Workaround on adding files or shortcuts to Quick Access in Windows 10

This afternoon, another MVP asked a question, how do we add a file or shortcut to Quick Access in Windows 10. He would like to do the same action as he could add a file or shortcut to Favorites in Windows 8 or before.

In Windows 10, “Favorites” is replaced by “Quick Access”. The “Quick Access” is letting you to browse into any folder in shortest route. If you want to add any folders to “Quick Access”, you could right click any folder and add it to “Quick Access” by selecting “Pin to Quick Access”.

After you pinned it to “Quick Access”, you could then remove it by right click and select “Unpin from Quick Access”.

But if you right click to any files or shortcuts, you will found out that there is no such option to add them into Quick Access. But if the files or shortcuts are often being executed, you could find it from the lower section of the Quick Access, “Recent Files”. But what about if they are not being executed often and you still want to add it to “Quick Access”? One of the work around way is, adding the Favorites to “Quick Access”. With this workaround, you could add any files or shortcuts to the Favorites and it will then appear to the Quick Access. On the other hand, it will be removed from “Quick Access” if you remove it from Favorites. The Favorites path in windows Explorer is “C:\Users\(username)\Links”.

Here is the regedit nodes that you have to add in order to enable “Favorites” add to “Quick Access”.


[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HomeFolderDesktop\NameSpace\DelegateFolders\{d34a6ca6-62c2-4c34-8a7c-14709c1ad938}]
@=”Common Places FS Folder”


[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\HomeFolderDesktop\NameSpace\DelegateFolders\{d34a6ca6-62c2-4c34-8a7c-14709c1ad938}]
@=”Common Places FS Folder”

And here is the regedit nodes that you have to remove in order to disable “Favorites” add to “Quick Access”.

[-HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\HomeFolderDesktop\NameSpace\DelegateFolders\{d34a6ca6-62c2-4c34-8a7c-14709c1ad938}]


[-HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\HomeFolderDesktop\NameSpace\DelegateFolders\{d34a6ca6-62c2-4c34-8a7c-14709c1ad938}]



Please note, You will need Administrator right to pass the UAC when you add/remove the regedit nodes.