Common Asp.Net Tips and Tricks


Introduction

This article is useful for all developer who faces this type of exception in their software development time. Article also provides tips for common error. I will provide you solution of common exception and issue facing during development.

Tips and Tricks


1) 500 Error occurs while publishing website in IIS. Most configuration error occurs because of this.
 Solution
Figure1: Configuration Steps related to publish website in IIS
Step 1: Choose appropriate application pool and if target framework is missing  in application pool then follow below steps as per your pc.
  • Open command Prompt using Run as administrator 
  • Change the directory path for proper framework in command prompt
CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
After changing directory path hit enter "aspnet_regiis i" this command register aspnet_regiis is available into directory.
Step 2: Select proper publish code 

Step 3: Check the Physical path is accessible for current user or IUSR by verify using “Test Settings”
2) If you have publish your website to live server and you want to change some minor code behind file and want to upload to live server what is best way?
Solution: Instead of publish whole site,
Step 1: Just build the project without error and go to project bin folder find "projectname.dll" and "projectname.pdb" (If available)

Step 2:Then put this two file to live project's bin folder and just replace it. Now Website runs with latest change. Because all our .cs file(code behind file) is converted to DLL and our page searches method reference from DLL file.

3) How to resolve "Maximum request length exceeded" Exception while working with web service or JSON data.
 Solution: The 4MB default is set in machine.config, but you can override it in you web.config. For instance, to expand the upload limit to 20MB, add below code to web.config:
     
IIS7(and later version) has a built-in request scanning which imposes an upload file cap which defaults to 30MB. To increase it, you also need to add the lines below
    
        
             
    
4)  The request filtering module is configured to deny a request that

exceeds the request content length (IIS 7)

Solution: You have to add below configuration to web.config file



    
        
             
    


5)  The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler.If the file should be downloaded,add a MIME map(For Json file)

Solution:  You have to add below configuration to web.config file


    
         

    

6)     When I integrating WebAPI2 in existing MVC web application some dependency error occurs.

Solution:

I have reinstall "system.web.http.webhost" package using Nuget and add WebApiConfig file. In ”appstart” folder  and register  to global.asax file before RouteConfig. If routeconfig added before webapiconfig then WebApi not working properly.

WebApiConfig.cs

public static void Register(HttpConfiguration config)   
{  
// Web API routes
    config.MapHttpAttributeRoutes();  

    config.Routes.MapHttpRoute(  
    name: "DefaultApi",  
    routeTemplate: "api/{controller}/{id}",  
    defaults: new
    {  
        id = RouteParameter.Optional  
    });  
//To return json format data
    config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));  
}
In global.asax file
AreaRegistration.RegisterAllAreas();  
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);  
//added before RouteConfig
GlobalConfiguration.Configure(WebApiConfig.Register);  
RouteConfig.RegisterRoutes(RouteTable.Routes);  
BundleConfig.RegisterBundles(BundleTable.Bundles); 

7)   How to speedup page request in asp.net

Solution:  Just add below configuration to web.config file and it will take care automatically.

    
        
        
            
            
            
            
        
        
            
            
            
            
        
    
    



Conclusion:

In this article we learn basic configuration tips as well as common exception and its solution which is common while developing web application. I will update this article with other useful tips

1 comment:

  1. really you have posted an informative blog. it will be really helpful to many peoples. thank you for sharing this blog. before i read this blog i didn't have any knowledge about this but now i got some knowledge.
    dot net training in chennai

    ReplyDelete

Dynamic Query in LINQ using Predicate Builder

Introduction This tutorial explain how to create dynamic query using LINQ, Using Predicate Builder  LINQ to SQL dynamic query and Q...

Learn More