Preventing your outlook.com from junk emails: Safe senders

This is the part of the article series ‘preventing your outlook.com from junk emails’. In this entry we will discuss about the Safe senders. Safe senders are are the email accounts who is allowed to send you email. E-mails from safe senders will not be sent to the junk email folder of your outlook.com email account. Continue reading “Preventing your outlook.com from junk emails: Safe senders”

How to show Indian currency symbol in MVC WebGrid

is the new Indian Rupee currency sign.it was presented to the public by the Government of India on 15 July 2010. When you try to show ₹ currnecy symbol using Culture and UCulture, you get the default currency symbol ‘Rs’ not ₹ then you need to set customize the symbol. Same problem occurs when you want to show this symbol in WebGrid in MVC projects. Continue reading “How to show Indian currency symbol in MVC WebGrid”

Generate xml document with elements and attributes using LINQ to XML

To generate a XML document with elements and attributes is easy by using LINQ to XML. LINQ to XML provides the XDocument, XElement and XAttribute classes,with the help of XElement class we can create XML content and create a new XML file using the XDocument class. Continue reading “Generate xml document with elements and attributes using LINQ to XML”

Create the XML document using LINQ to XML in C#

XML document is widely used file in the projects where we can store the small or big data such as configuration settings or last used data on the form. .Net framework provides various way to create the XML files (such as DataSet.WriteXML), but my concern it is so easy to create the XML document by using the LINQ to XML. Continue reading “Create the XML document using LINQ to XML in C#”

How to Create System Restore Point from VB.net

System Restore Point is a very useful feature of Windows Operation System. This is basically used when we got some issue with OS because of any new installation. By the help of this feature we can easily restored our OS with any previous date when this point was created (but we will lost all data which we save or installed after restored point date so be careful about it). Continue reading “How to Create System Restore Point from VB.net”

Bind DropdownList box from the Enum values in MVC4

Yesterday i need to bind a DropDownList control with the Enum type. I have been using the html.DropDownList(name as string, IEnumerable <SelectListItem > ) method to bind show the list of the items but this method need the IEnumerable <SelectListItem > and i have a Enum type. Suppose you have a Enumeration in your model like this:

 Public Enum DepartmentList
        Sales
        HR
        Marketing
        Production
    End Enum

You can not use this statement, it will gives an error: ‘DepartmentList is the type in model you can use as expression

  <%-- This is the Wrong way -->
   <%: Html.DropDownList("test", Model.DepartmentList)%>

So i discover a way to change the Enum type in the array and then cast in to SelectList. And you can do that in a single statement like as:

<div>
Select Department: @Html.DropDownList("lstdepartment", 
                   new SelectList(Enum.GetValues
                      (typeof(MvcApplication1.Models.Employee.Deaprtmentlist))))
</div>

To Retrieves an array of the values of the constants in a enumeration, we can use the Enum.GetValues() method.

Render <, >, and & characters in Web Browser in Visual Basic

Some time When you need to use some characters as text like <,> and & in your web page, browsers understand these characters as the part of the html tags and they rendered incorrectly these characters unless characters are escaped as <, >, and & respectively.

This scenario is same in Web browser control in .net. Web browser also rendered these characters incorrectly.
See the following string:

Dim RenderString as String="Welcome to <Authorcode>"

For the correct rendering of above string, we need to encode this string. You can encode this string with the help of System.Web.Server.HtmlEncode() method.

Dim RenderString as String="Welcome to <Authorcode>"
Dim EncodedString As String = Server.HtmlEncode(RenderString )

Server.HtmlEncode() method requires to import the System.Web assembly so add the reference this dll in your project.

How to disable Session state on your asp.net page

Every asp.net page has the session state by default, this may decrease the total performance a little bit. So You can disable the session state from the pages when you don’t need to use sessions. And you can do so to set the false value of the EnableSessionState attribute in the page directive of your page like as: Continue reading “How to disable Session state on your asp.net page”

How to use Session Events: Session_OnStart and Session_OnEnd

There are two important session events related to session state in asp.net, one is Session_OnStart and another is Sesson_OnEnd. You can use both events in the Global.asax file in your asp.net application or websites. The Session_Start event is raised when first time session starts and Sesosion_End event raises whenever session end. Global.ascx file must be located in the root directory of the application. So you just need to create two subroutine in the Global.ascx file as:

Public Sub Session_OnStart()
 
End Sub
 
Public Sub Session_OnEnd()
 
End Sub

We can understand these event by taking a simple example to show the Number of the active users of the website. In this example we will create a counter by adding 1 in the application state variable ‘NoOfOnlineUsers’ on the session start and subtracting 1 from this variable on the session end

public void Application_OnStart()
{
  Application["NoOfOnlineUsers"] = 0;
}
 
public void Session_OnStart()
{
  Application["NoOfOnlineUsers"] = (int)Application["NoOfOnlineUsers"] + 1;
}
 
public void Session_OnEnd()
{
  Application["NoOfOnlineUsers"] = (int)Application["NoOfOnlineUsers"] - 1;
}

From the above example you can understand the basics of the both events if you want to do more then you could do so by using these events. You can also use these events to track some more session-related information.

One more things as MSDN says ‘If the Global.asax file or Web.config file for an ASP.NET application is modified, the application will be restarted.‘ this means your Application[“NoOfOnlineUsers”] value will be zero if you modified these files.

If some person does not do any action on the a page or page remains idle for some specified time then web server assumes that user left the page and then Session_OneEnd event will be raised.