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
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”
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
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")); }
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.
Comments
Post a Comment