Sunday 19 April 2015

ASP.net Unable to read resource bundle


Scripts.Render("~/bundles/modernizr")

Just add the Following in the module section the web.config file


 <remove name="BundleModule" />
 <add name="BundleModule" type="System.Web.Optimization.BundleModule" />

ASP.NET Routing and IIS 404 errors

ASP.NET Routing is a powerful feature introduced in .NET 3.5 SP1 and included with .NET 4.0 that allows a developer to route URL's that are not real files. There are several ways you can accomplish this same task, but having it in the ASP.NET pipeline allows the developer great flexibility in how URL's are routed. However, it does not always work "out-of-the-box" for devs. The most common error I've seen is a 404 error – meaning the page cannot be found.
There can be several contributing factors. If you are attempting to utilize extenionless URL's, ensure you have the appropriate IIS hotfix installed: http://support.microsoft.com/kb/980368. More commonly however, the issue is a result of the module not firing for your request type. The easy fix is to add runAllManagedModulesForAllRequests=”true” to the modules tag in your web.config. However, that could have performance implications as you are now telling IIS to ignore the preCondition setting for all modules. The alternative solution is to remove the managedHandler preCondition for the URLRouting module:
    <modules>
      <remove name="UrlRoutingModule" />
      <add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
    </modules>

or   <system.webServer>
    <modules runAllManagedModulesForAllRequests="true">     
    </modules>
  </system.webServer>
or  Download and install the extension to the IIS support.microsoft.com

Thursday 16 April 2015

asp.net write script in the page at run-time

There are many ways to write scripts inside html page using c# code behind, some of them

The following code snippet will append the script at the end of the page

ClientScript.RegisterStartupScript(this.GetType(), "keyOfScript", "console.info('Mohammad');", true);

The following code snippet will append the script at the beginning of the page

Response.Write("< script >console.info('Mohammad');< / script>");