Sunday, March 27, 2016

404 error for .woff font file in asp.net

When you use font awesome in asp.net, you get the 404 file not found error for the font files.

Error:

Failed to load resource: the server responded with a status of 404 (Not Found).
http://localhost/web-led/font-awesome/fonts/fontawesome-webfont.woff2?v=4.3.0



Fix:
This can be fixed by adding the mime type in the web config, under the system.webServer section

<system.webServer>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
    </staticContent>    
</system.webServer>


As mentioned by Deepak in the comments, if you have access to the iis you can easily set it from IIS itself. 

Monday, March 21, 2016

Identify Anonymous Users in Asp.net

Identify anonymous users in asp.net

The first thing when we read about identifying anonymous users in asp.net mvc is "Why do we need to identify anonymous users?". Well the same thought had crossed my mind, but then when developing an e-commerce application, we needed anonymous users to add items to the shopping cart without logging in. We also needed these items to be loaded into the shopping cart, the next time they visited.

How do we do this?

Asp.net provides a guid accessed through the Request.AnonymousId property with which the user can be identified.
  1. Enable anonymous Identification

    Anonymous Identification need to be enabled, else Request.AnonymousId will be null.
    <configuration>
        <system.web>
          <anonymousIdentification enabled="true"/>
        </system.web>
      </configuration>
  2. Access the Anonymous Id

    Anonymous Id can be accessed through Request.AnonymousID property.

Hope this helps someone.