20 Dec: Must Read Codes [6-10]
Dec20

20 Dec: Must Read Codes [6-10]

Welcome to CodeSpread! We are sharing few must read codes/concepts which are required now and then. Each of these codereads doesn’t require a full length descriptive article so combining them into groups of five. CodeReads #6, What is the difference between Dispose and Finalize? #Point 1, Dispose is used to release unmanaged resources in a deterministic fashion, like we know when to release the resource. Finalize method is also used for the purpose of releasing resources but in non-deterministic fashion like we cannot be sure as when Garbage Collector will collect the resource. #Point 2 , Finalize method has a performance drawback due to the Garbage Collector as there will be two iterations of Garbage Collector and override operation. fbsource :https://www.facebook.com/codespread/posts/550605628295996 CodeReads #7, Garbage Collector maintains managed objects in “generations.” The generation indicates the lifetime of an object like objects having short life are stored in lower generations as GC runs much more frequently to clean up objects in the lower generations. The more the objects survive a GC cleanup, the more the chances that these objects will get moved to higher generations. There will be few GC swipes on higher generations and also that will happen only if lower generations have no space left. When we talk about generations, we talk about physical memory locations divided,managed and allocated to each generation number. fbsource: https://www.facebook.com/codespread/posts/550949951594897 CodeReads #8, .data() : Store arbitrary data associated with the matched elements or return the value at the named data store for the first element in the set of matched elements. For more information: http://api.jquery.com/data/ fbsource: https://www.facebook.com/codespread/posts/370621346386549 CodeReads #9, Elements of a UML Class Diagram are: Class Operations Relationships -Associations -Generalization -Dependency -Realization Constraint Rules and Notes fbsource: https://www.facebook.com/codespread/posts/552364564786769 CodeReads #10, Scaffolding is a technique in which the programmer may write a specification that describes how the application database may be used. With the help of this concept,programmer can create a functional Web site for viewing and editing data based on the schema of the data. ASP.NET Dynamic Data supports scaffolding. Refer the below link. For more information: http://msdn.microsoft.com/en-IN/library/ee845452%28v=vs.100%29.aspx fbsource:...

Read More
19 Dec: Must Read Codes [1-5]
Dec19

19 Dec: Must Read Codes [1-5]

We are sharing few must read codes/concepts which are required now and then. Each of these codereads doesn’t require a full length descriptive article so combining them into groups of five. CodeReads #1, Usage of ‘this’ keyword in C#. To qualify members hidden by similar name. To have an object pass itself as a parameter to other methods. To have an object return itself from a method. To declare indexers. To declare extension methods. To pass parameters between constructors. To internally reassign value type (struct) value. fbsource: https://www.facebook.com/codespread/posts/544740368882522 CodeReads #2, ISNULL and COALESCE though equivalent, can behave differently. An expression involving ISNULL with non-null parameters is considered to be NOT NULL, while expressions involving COALESCE with non-null parameters is considered to be NULL. fbsource: https://www.facebook.com/codespread/posts/545045568852002 CodeReads #3, Regular Cast: string str= (string) strToCast; Method Call: string str= strToCast.ToString(); Safe Cast: string str= strToCast as string; fbsource: https://www.facebook.com/codespread/posts/545045568852002 CodeReads #4, Control State maintains the behavior of the controls whereas View State maintains the content of the controls. Also, Control State is available even though View State for the control is disabled. fbsource: https://www.facebook.com/codespread/posts/547846855238540 CodeReads #5, In javascript, Body.Onload() event occurs only after the DOM has been loaded, plus all associated resources like images, flash etc are also completely loaded. $(document).ready() occurs when the DOM has been loaded but associated resources like images, flash etc may be pending. There can be multiple document.ready() in a page but Body.Onload() event will be only one. fbsource:...

Read More
ASP.NET and Web Tools 2013.1 for Visual Studio 2012
Nov21

ASP.NET and Web Tools 2013.1 for Visual Studio 2012

.NET Web Development and Tools group at Microsoft announces release of ASP.NET and Web Tools 2013.1 for Visual Studio 2012. Few of the features are: 1) Round tripping: With this update, developers working on Visual Studio 2012 and Visual Studio 2013 can collaborate on an ASP.NET MVC 5 application. It provides support for editing a Razor view like syntax highlighting and Intellisense. 2) ASP.NET MVC 5 and Web API 2 Templates. 3) ASP.NET Scaffolding: With this update, MVC’s scaffolding can be used within any ASP.NET project. 4) ASP.NET Razor Tooling: As discussed above, new features are available like syntax highlighting and Intellisense. 5) Entity Framework 6. 6) Bootstrap: Bootstrap is a responsive mobile first CSS framework for styling the pages. 7) NuGet 2.7. This can downloaded from here:...

Read More
Error Handling at Page level or Application level
Oct10

Error Handling at Page level or Application level

A regular query of a developer as which is the best way to handle errors? at Page level or Application level. Best answer is why to chose one over the other? Lets have both. We will try some sample for Page level Error Handling and Application level Error Handling. How to Handle errors at Page level? To catch errors, the best way available is Try/Catch block on code file. public void Calculate() { try { //Do some Calculation } catch(Exception ex) { //Log Exception } } In the above sample, an exception can be corrected at the same time it occurred. We have another way where a page-level error handler can be created to catch any exceptions that are not caught within Try/Catch block. private void Page_Error(object sender, EventArgs e) { // Get last error Exception ex = Server.GetLastError(); if (ex is InvalidOperationException) { // Handle or Log exceptions } } Note: If the handler can’t resolve the exception,control is transferred to the error handler in the Global.asax file and is handled at application level. Still the exception remains unresolved, Web.config file can be configured to redirect the site to redirect to the generic page specified. Refer Custom Errors. How to Handle errors at Application level? To Handle errors at Application level,create an error handler in the Global.asax file. void Application_Error(object sender, EventArgs e) { // Get the last error. Exception ex = Server.GetLastError(); // Handle HTTP errors if (ex.GetType() == typeof(HttpException)) { //Handler Implementation //Redirect to Error page Server.Transfer("Error.aspx"); } // Clear the error from the server Server.ClearError(); } Global.asax file cannot be used to show error information so server.transfer is used to maintain current context and transfer it to another webpage like an error page. Here, the error information can be shown. Note: Avoid showing compromising information about the Web site directly to the...

Read More
Custom error mode in ASP.NET web.config
Sep03

Custom error mode in ASP.NET web.config

Dual Roles As a developer, I would love to see the error page that provides details of the error, status code and also the stack information. This information is useful to debug the application but soon becomes an ugly yellow page when I switched my role from developer to user. Who wants to see an ugly yellow page? Just a developer (sigh!) Here comes the custom error page to the rescue, from yellow page,to indicate an error. We just have to bring some configuration changes in the ><customErrors> section of our web.config file. How we add custom error configuration? Custom 404 and 500 errors are typically used to redirect the user to the error page. Let’s see an example, <customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"> <error statusCode="403" redirect="NoAccess.htm" /> <error statusCode="404" redirect="FileNotFound.htm" /> </customErrors> We can see that the mode selected is RemoteOnly. we have, in all 3 modes: 1) Off Mode: It signifies that custom errors are disabled. In this mode, the same ugly error page is shown which we, as a developer, consider helpful for debugging purpose. 2) On Mode: It signifies custom errors are enabled, and as discussed above, user is redirected to a custom error page. In the above example, user may be redirected to NoAcess.htm or FileNotFound.htm on specific errors. 3) RemoteOnly Mode: Same as ON Mode, custom errors are enabled. The difference lies in the request originating from, like if the request originates from a remote machine page is redirected to custom error page else if the request originates from the local machine the default error page is shown. Selecting a mode is a mandatory action.The default mode is RemoteOnly. We have “defaultRedirect” element which is optional and as the name suggests, user is redirected to a default URL. Two lines of configuration and relaxed eyes of user enhances user’s...

Read More
Page 1 of 512345