Introduction
This article is useful for developers encountering exceptions during development. It also provides some tips for common errors and gives a solution for common exceptions and issues encountered during development.
Tips and Tricks
1. The 500 Error occurs when publishing a website in IIS. The most configuration errors occur due to this.
SolutionFigure 1: Configuration procedure related to publishing website in IIS
Step 1: Choose the appropriate application pool and if the target framework is missing in the application pool, use the following procedure depending on your Windows system.
- Open a command prompt using Run as administrator.
- Change the directory path for the proper framework in the command prompt.
CD C:\Windows\Microsoft.NET\Framework64\v4.0.30319
- After changing the directory path hit Enter "aspnet_regiis i", this command registers aspnet_regiis availability into the directory.
Step 2: Select proper publish code.
Step 3: Check that the physical path is accessible for the current user or IUSR by verifying using “Test Settings”.
2. If you have published your website to a live server and want to change some minor code behind file and upload it to live server, then what is the best way?
Solution:
Instead of publishing the complete site, use the following:
Step 1: Just build the project without error and go to the project bin folder, then find "projectname.dll" and "projectname.pdb" (if available).
Step 2: Then put those two file into the live project's bin folder and just replace it. Now the website runs with the latest changes because our .cs file (code behind file) is converted to a DLL and our page searches for the method reference from the DLL file.
3. Now to resolve the "Maximum request length exceeded" exception when working with a 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 the following code to the web.config:
- <system.web>
- <httpRuntime executionTimeout="240" maxRequestLength="20480" />
- </system.web>
IIS7 (and later versions) has a built-in request scanning that imposes an upload file cap that defaults to 30MB. To increase it, you also need to add the following lines:
- <system.webServer>
- <security>
- <requestFiltering>
- <requestLimits maxAllowedContentLength="3000000000" />
- </requestFiltering>
- </security>
- </system.webServer>
4. The request filtering module is configured to deny a request that exceeds the request content length (IIS 7).
Solution
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
6. When I integrated WebAPI2 into an existing MVC web application then some dependency error occurred.
Solution
I reinstalled the "system.web.http.webhost" package using Nuget and added a WebApiConfig file to the ”appstart” folder. Now register to the global.asax file before RouteConfig. If RouteConfig was added before webapiconfig, then the WebApi stops working properly.
WebApiConfig.cs
- public static void Register(HttpConfiguration config)
- {
-
- config.MapHttpAttributeRoutes();
-
- config.Routes.MapHttpRoute(
- name: "DefaultApi",
- routeTemplate: "api/{controller}/{id}",
- defaults: new
- {
- id = RouteParameter.Optional
- });
-
- config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
- }
In global.asax file
- AreaRegistration.RegisterAllAreas();
- FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
-
- GlobalConfiguration.Configure(WebApiConfig.Register);
- RouteConfig.RegisterRoutes(RouteTable.Routes);
- BundleConfig.RegisterBundles(BundleTable.Bundles);
7. How to speedup page request in ASP.NET.
Solution
Conclusion
In this article we learned some basic configuration tips as well as common exceptions and their solution. These exceptions occur frequently when developing web applications. I will update this article with other useful tips.