Senator Guerra Souty original series calendar,replica hublot blue steel peach pointer collocation of rolex replica Rome digital scale, track type minute replica watches scale shows that the classical model is swiss replica watches incomparable, wearing elegant dress highlights.
mr-ponna.com

 

YOU ARE HERE: HOME Articles Page 1

ASP.NET, C# and SQL Server articles and tutorials

Read ASP.NET, C# and SQL Server articles

Sort by:

<< Start < Prev 1 2 Next > End >>
Page 1 of 2

ASP.NET, C# and SQL Server articles and tutorials

# articles: 18  


Encrypt connectionStrings section of web.config

View(s): 8749

Encrypt connectionStrings section of web.config

Web.Config
<configuration>
    <connectionStrings>
        <add name="ConnString" connectionString="Data Source=.\SQLEXPRESS; 
AttachDbFilename=|DataDirectory|MyDatabase.mdf;Integrated Security=True;User Instance=True" />
    </connectionStrings>
</configuration>


The easiest way to encrypt the <connectionStrings> section is to use the aspnet_regiis command-line tool.
This tool is located in the following folder:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\

Executing the following command encrypts the <connectionStrings> section of a Web.Config file
located in a folder with the path c:\Websites\MyWebsite:
   
    aspnet_regiis -pef connectionStrings "c:\Websites\MyWebsite"

The -pef option (Protect Encrypt Filepath) encrypts a particular configuration section located at a particular path.

You can decrypt a section with the -pdf option like this:

    aspnet_regiis -pdf connectionStrings "c:\Websites\MyWebsite"

ASP.NET page can read the value of the connection string by using the <%$ ConnectionStrings:ConnString %> expression

(Continued...) View Full Aritlce


  Last updated on Friday, 11 July 2014
  Author: Mr. Ponna
4/5 stars (4 vote(s))



Detecting Refresh or Post back in ASP.NET

View(s): 9488

Detecting Refresh or Post back in ASP.NET


The problem
There are situations where we would like to detect if the post back is from a form interaction (i.e. submit or button clicks) or is it by hitting the browser F5 refresh button. 

Many of them will jump saying how about checking 'Ispostback' value. 'IsPostback' will always have the value which was set previously. So for instance if the page was posted back before refresh, then the value will be true and if the page is not posted back before refresh, then the value will be false.

This article will first explain the fundamentals of how to solve the above problem and later this article will go in depth of how the source code looks like.

The fundamental

Description: 12.jpg

  • Step 1 :-We have created a javascript which will generate unique fresh GUID in submit button click. This GUID will be stored in the HttpContext object.
  • Step 2( User presses submit click ) :- If user presses submit button it will call the necessary javascript function to create the new fresh GUID again. 
  • Step 3 :-In 'HttpHandler' or 'HttpModule' the new GUID value is checked with the old GUID value. If the values are not equal then it means this was not called from a submit click and it's a refresh event. Accordingly the HttpContext session value is set.
  • Step 4 :-In the page load we can then check if this was a refresh or post back using the session variables.

3 important parts of the code

There are 3 important part of the code to be understood :-

  • Javascript which generates the unique
(Continued...) View Full Aritlce


  Last updated on Saturday, 21 June 2014
  Author: Mr. Ponna
4/5 stars (8 vote(s))



Send Email Using Gmail in ASP.NET

View(s): 14523

Send Email Using Gmail in ASP.NET

If you want to send email using your Gmail account or using Gmail's smtp server in ASP.NET application or if you don't have a working smtp server to send mails using your ASP.NET application or aspx page than sending e-mail using Gmail is best option.

you need to write code like this

First of all add below mentioned namespace in code behind of aspx page from which you want to send the mail.

using System.Net.Mail;

Now write this code in click event of button 

C# code

protected void Button1_Click(object sender, EventArgs e)
{
  MailMessage mail = new MailMessage();
  mail.To.Add("xyz@gmail.com");
  mail.To.Add("abc@yahoo.com");
  mail.From = new MailAddress("YourUserName@gmail.com");
  mail.Subject = "Email using Gmail";
  string Body = "Hi, this mail is to test sending mail"+
                "using Gmail in ASP.NET";
  mail.Body = Body;
  mail.IsBodyHtml = true;
  SmtpClient smtp = new SmtpClient();
  smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
  smtp.Credentials = new System.Net.NetworkCredential
       ("YourUserName@gmail.com","YourGmailPassword"); //Or your Smtp Email ID and Password
  smtp.EnableSsl = true;
  smtp.Send(mail);
}


VB.NET code 

Imports System.Net.Mail

Protected  Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

(Continued...) View Full Aritlce


  Last updated on Sunday, 01 June 2014
  Author: Mr. Ponna
3/5 stars (10 vote(s))



The C# Programming Language Version 4.0

View(s): 7520

The C# Programming Language Version 4.0

Visual Studio 2010 and the ..NET Framework 4.0 will soon be in beta and there are some excellent new features that we can all get excited about with this new release. Along with Visual Studio 2010 and the .NET Framework 4.0 we will see version 4.0 of the C# programming language. In this blog post I thought I'd look back over where we have been with the C# programming language and look to where Anders Hejlsberg and the C# team are taking us next.

In 1998 the C# project began with the goal of creating a simple, modern, object-oriented, and type-safe programming language for what has since become known as the ..NET platform. Microsoft launched the .NET platform and the C# programming language in the summer of 2000 and since then C# has become one of the most popular programming languages in use today.

With version 2.0 the language evolved to provide support for generics, anonymous methods, iterators, partial types, and nullable types.

When designing version 3.0 of the language the emphasis was to enable LINQ (Language Integrated Query) which required the addiiton of:

  • Implictly Typed Local Variables.
  • Extension Methods.
  • Lambda Expressions.
  • Object and Collection Initializers.
  • Annonymous types.
  • Implicitly Typed Arrays.
  • Query Expressions and Expression Trees.

If you're in need of learning about, or distilling knowledge of, any of these language features that I have mentioned

(Continued...) View Full Aritlce


  Last updated on Monday, 12 May 2014
  Author: Mr. Ponna
0/5 stars (0 vote(s))



C# .NET 2.0 Test Driven Development

View(s): 7187

C# .NET 2.0 Test Driven Development

Overview

There are many benefits of test driven development including better end product with well defined supporting unit tests and having a programming paradigm that is a bit more flexible in regards to scope changes.  Having unit tests available will make our code more maintainable over the long run is invaluable because we can modify our code without fear such as when we are adding/modifying functionality or refactoring.  It could even be considered crucial when we have projects where the scope is likely to change throughout the development lifecycle like in the case where the functional specifications are not clearly defined before we begin producing code.

Test driven development can be a huge shift in the development approach for many of us.  The test driven approach basically chips away at the solution like a sculptor would at a marble block instead of trying to define and create a monolithic application in one shot.

As a first step, we'll define the interfaces out software will adhere to.  The interface should clearly define how our class is to interact with other classes and what information it will expose.  This is a crucial step in any software design process because we really have to know where we are going and the interface serves as a map that will help us get there.

After we have an interface, we'll begin with the test-driven development cycle. 

  1. Add a test
  2. Run all tests and watch the new one fail (and the
(Continued...) View Full Aritlce


  Last updated on Tuesday, 22 April 2014
  Author: Mr. Ponna
3/5 stars (1 vote(s))



C# yield operator

View(s): 8907


C# yield operator


Prior to .NET 2.0, the only way you could create your own collection which could be traversed using the 'foreach' construct was by having you class implementing the IEnumerable and IEnumerator Interfaces.

However since .NET 2.0 we have a new operator called 'yield'. This allows your class to be iterated by its consumer but without the need to implement the above-mentioned interfaces.

Let us see a small example of how this works:

// Our class does not implement any interface !
public class School
{
    // Explicit initialization just for demo purposes !
    private string[] studentNames = {"John", "Joan","Joanne", "Tony", "Peter"};

    // The iterating method
    public IEnumerator GetEnumerator()
    {
        foreach (string name in studentNames)
        {
            // yield return in action !
            yield return name;
        }
    }
}

And now the code for the consumer:

class Program
{
    static void Main(string[] args)
    {
        School NorthCoast = new School();
        // How School's internal collection was iterated is hidden to the user
        foreach (string student in NorthCoast)
        {
  
(Continued...) View Full Aritlce


  Last updated on Wednesday, 02 April 2014
  Author: Mr. Ponna
4/5 stars (4 vote(s))



What are Master Pages in .NET? Why we need Master Pages and how do we use Master Pages in our applications?

View(s): 20098


What are Master Pages in .NET? Why we need Master Pages and how do we use Master Pages in our applications?


Life before Master Pages

For a given website, there are multiple web pages with common layout. How we can achieve this?

  • Write the layout of the code in each page. But this leads to code redundancy which is not correct.
  • We can achieve the common layout, by using User controls.

Advantage of User Controls:

  • Turning an existing ASP.NET page into a user control requires only a few minor changes. User controls can be easily linked to any page that needs their services.
  • Furthermore, changes to a user control's implementation do not affect the referencing page and only require recompiling of the user control into an assembly.

Disadvantage of User Controls:

  • Any alteration to the control's public interface (such as the class name, properties, methods, or events) leads to the pages that reference the control must be updated.
  • Those pages must be re-compiled and needs deployment.
  • In addition, the next time a user views each page, the ASP.NET runtime will take a while to respond because the dynamic assembly for the page must be re-created.

Apart from the above two options, the other options is to use Master pages. A Master page is a file that contains the static layout of the file. It consists of the layout that is common throughout application (i.e. Application Level) or a folder level and dynamic parts will be customized by the pages that are derived from the Master page.

(Continued...) View Full Aritlce


  Last updated on Thursday, 13 March 2014
  Author: HariSantosh Kadiyala
3/5 stars (12 vote(s))



Creating Windows Services with Visual Studio 2008

View(s): 14160

Creating Windows Services with Visual Studio 2008

A Windows services is a application that runs in the background.  There is documentation on the Web for creating a Service with Visual Studio 2003, but is is changed for VS 2005, and 2008.

I will walk thru a sample Service in Visual Studio 2008.  This should also work with VS 2005.

Create the Service.

Description: Description: servicecreate

From Visual Studio Start Page, choose create project…   Select Windows Service and give it a name of NewService.

Description: Description: serviceblank

First thing we will do is add a timer to the Service.  DO NOT USE THE TIMER IN THE TOOLBOX.  The Timer for Windows Forms does not work for Services.  We will have to find the System.Timers.Timer component by right clicking on the Toolbox, and Choose Items.

Find the one that matches below:
Description: Description: servicetimerchoose

Click OK.  This will put the Timer into the Printing section of the Toolbar for some reason.

From The Service1 designer.  Click on Timer1, and set the interval to 10000 (10 Seconds).  Then Double-click to open Code View for Timer1_Elapsed.


Add the Following Code to the Timer1_Elapsed:

Dim MyLog As New EventLog() 
‘ create a new event log 
‘ Check if the the Event Log Exists

If Not 
MyLog.SourceExists(“NewService”) Then 
MyLog.CreateEventSource(“NewService”, “NewService_Log”) ‘ Create Log
End If 

MyLog.Source = “NewService” ‘ Write to the Log 
MyLog.WriteEntry(“NewService_Log”, “Service is Running” _ , EventLogEntryType.Information)

End Sub

And For OnStart():

Protected Overrides

(Continued...) View Full Aritlce


  Last updated on Friday, 21 February 2014
  Author: Mr. Ponna
2/5 stars (2 vote(s))



Implementing the Singleton Pattern in .NET

View(s): 8850


Implementing the Singleton Pattern in .NET

The intent of the Singleton pattern as defined in Design Patterns is to "ensure a class has only one instance, and provide a global point of access to it".

What problem does this solve, or put another way, what is our motivation to use it? In nearly every application, there is a need to have an area from which to globally access and maintain some type of data. There are also cases in object-oriented (OO) systems where there should be only one class, or a predefined number of instances of a class, running at any given time. For example, when a class is being used to maintain an incremental counter, the simple counter class needs to keep track of an integer value that is being used in multiple areas of an application. The class needs to be able to increment this counter as well as return the current value. For this situation, the desired class behavior would be to have exactly one instance of a class that maintains the integer and nothing more.

At first glance, one might be tempted to create an instance of a counter class as a just a static global variable. This is a common technique but really only solves part of the problem; it solves the problem of global accessibility, but does nothing to ensure that there is only one instance of the class running at any given time. The responsibility of having only one instance of the class should fall on the class itself and not on the user of the class. The users of the class should always

(Continued...) View Full Aritlce


  Last updated on Saturday, 01 February 2014
  Author: rajeeva.nagarakanti
3/5 stars (4 vote(s))



Serialization and Types of Serialization in .Net

View(s): 17680


Serialization and Types of Serialization in .Net


Serialization:

  1. Serialization is a process of converting an object into a stream of data so that it can be is easily transmittable over the network or can be continued in a persistent storage location.  This storage location can be a physical file, database or ASP.NET Cache.
  2. Serialization is the technology that enables an object to be converted into a linear stream of data that can be easily passed across process boundaries and machines.  This stream of data needs to be in a format that can be understood by both ends of a communication channel so that the object can be serialized and reconstructed easily.

Advantage:

Using serialization is the ability to transmit data across the network in a cross-platform-compatible format, as well as saving it in a persistent or non-persistent storage medium in a non-proprietary format.

Serialization is used by Remoting, Web Services SOAP for transmitting data between a server and a client.  The Remoting technology of .NET makes use of serialization to pass objects by value from one application domain to another.

De-serialization is the reverse; it is the process of reconstructing the same object later.

Figure 1

Description: http://aspalliance.com/ArticleFiles/983/image001.jpg

Advantages and Disadvantages of Serialization

The following are the basic advantages of serialization:

  1. Facilitate the transportation of an object through a network
  2. Create a clone of an object 

The primary disadvantage

(Continued...) View Full Aritlce


  Last updated on Sunday, 12 January 2014
  Author: rajeeva.nagarakanti
5/5 stars (11 vote(s))

<< Start < Prev 1 2 Next > End >>
Page 1 of 2
Register Login Ask Us Write to Us Help