European ASP.NET 4.5 Hosting BLOG

BLOG about ASP.NET 4, ASP.NET 4.5 Hosting and Its Technology - Dedicated to European Windows Hosting Customer

ASP.NET 5 Hosting Italy - HostForLIFE.eu :: How to Create ImageButton Control in ASP.NET ?

clock January 9, 2015 05:35 by author Peter

With this post, I will tell you how to create ImageButton Control in ASP.NET 5. First, you need to declare ASP.NET ImageButton Control. Declare the ImageButton by the below code with property,As like Alternative text, ImageUrl,Height,Width.Image Button is predefined Asp.net web control Use in web development.

Declare ImageButton by fallowing code with property,As like Alternative text, ImageUrl,Height,Width.Image Button is predefined Asp.net web control Use in web development.
And here is the code:
<asp:ImageButton id="imagebutton1" runat="server"
    AlternateText="ImageButton 1"
    ImageAlign="left"
    ImageUrl="~/Images/image1.jpg"
    OnClick="ImageButton_Click" Height="148px" Width="274px"/>

For Access ImageButton by javascript we  use following code:
<script language="C#" runat="server">
  void ImageButton_Click(object sender, ImageClickEventArgs e)
      {
         Label1.Text = "You clicked ImageButton control at the coordinates: (" +
                       e.X.ToString() + ", " + e.Y.ToString() + ")";
      }
   </script>

The JavaScript code we get clicked position in Image.and print this on the Label Text.

Code of ASP.NET Image Control:
<%@ Page Language="C#" AutoEventWireup="True" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>ImageButton Sample</title>
<script language="C#" runat="server">
      void ImageButton_Click(object sender, ImageClickEventArgs e)
      {
         Label1.Text = "You clicked ImageButton control at the coordinates: (" +
                       e.X.ToString() + ", " + e.Y.ToString() + ")";
      }
  </script>
</head>
<body style="height: 261px">
   <form id="form1" runat="server">
      <h3>ImageButton Example:</h3>
      Click Anywhere on the image.<br /><br />
      <asp:ImageButton id="imagebutton1" runat="server"
           AlternateText="ImageButton 1"
           ImageAlign="left"
           ImageUrl="~/Images/Image1.jpg"
           OnClick="ImageButton_Click" Height="148px" Width="274px"/>
      <br />
      <br />
      <br />
      <asp:label id="Label1" runat="server"/>
      <br />
   </form>
</body>
</html>

Finally, this is the result:



ASP.NET 5 Hosting Russia - HostForLIFE.eu :: How to Preview Image Before Upload with jQuery in ASP.NET ?

clock January 5, 2015 05:13 by author Peter

With this article, I will explain you how to preview image before upload with jQuery using FileUpload in ASP.NET 5. While for the browsers that support HTML5 i.e. Internet Explorer, Mozilla FireFox, Google Chrome and Opera, the image preview will display usingHTML5 FileReader API. Preview image before upload using FileUpload control and jQuery in ASP.NET.

Method 1:
In this method 1, we will use the code below
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Preview image before upload using FileUpload control and jQuery in ASP.NET </title>
    <script src="http://code.jquery.com/jquery-1.10.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        function PreviewImageBeforeUpload(Imagepath) {
            if (Imagepath.files && Imagepath.files[0]) {
                var Filerdr = new FileReader();
                Filerdr.onload = function (e) {
                    $('#ImagePreview').attr('src', e.target.result);
                }
                Filerdr.readAsDataURL(Imagepath.files[0]);
            }
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FilePreview" runat="server" onchange="PreviewImageBeforeUpload(this);" />
        <br />
        <asp:Image ID="ImagePreview" runat="server" Width="150px" Height="150px" />
        <asp:Button ID="btnSubmit" runat="server" Text="Upload" />
    </div>
    </form>
</body>
</html>

Next, Method 2 will using the DXImageTransform filter CSS property in browsers that don’t support HTML5 i.e. Internet Explorer 8 and 9.

Method 2:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Preview image before upload using FileUpload control and jQuery in ASP.NET
    </title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script language="javascript" type="text/javascript">
        $(function () {
            $("#FilePreview").change(function () {
                $("#ImagePreview").html("");
                var regex = /^([a-zA-Z0-9\s_\\.\-:])+(.jpg|.jpeg|.gif|.png|.bmp)$/;
                if (regex.test($(this).val().toLowerCase())) {
                    if ($.browser.msie && parseFloat(jQuery.browser.version) <= 9.0) {
                        $("#ImagePreview").show();
                        $("#ImagePreview")[0].filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $(this).val();
                   }
                    else {

                        $("#ImagePreview").show();
                        $("#ImagePreview").append("<img />");
                        var Filerdr = new FileReader();
                        Filerdr.onload = function (e) {
                            $("#ImagePreview img").attr("src", e.target.result);
                        }
                        Filerdr.readAsDataURL($(this)[0].files[0]);
                    }
                } else {
                    alert("Please upload a valid image file.");
                }
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FilePreview" runat="server" />
        <br />
        <div id="ImagePreview" style="width: 150px; height: 150px">
        </div>
        <asp:Button ID="btnSubmit" runat="server" Text="Upload" />
    </div>
    </form>
</body>
</html>



HostForLIFE.eu Proudly Launches DotNetNuke 7.3.4 Hosting

clock December 23, 2014 07:47 by author Peter

European leading web hosting provider, HostForLIFE.eu announced support for DotNetNuke 7.3.4 hosting plan due to high demand of DotNetNuke CMS users in Europe.

HostForLIFE.eu proudly launches the support of DotNetNuke 7.3.4 on all our newest Windows Server  environment. HostForLIFE.eu DotNetNuke 7.3.4 Hosting plan starts from just as low as €3.00/month only and this plan has supported ASP.NET 5, ASP.NET MVC 5/6 and SQL Server 2012/2014.

DotNetNuke 7.3.4, as well known in the web industry and familiar among .NET developers, is a Web Content Management System (WCMS) based on Microsoft .NET platform. It is an excellent open source software that you can use to manage your website without having much technical knowledge.

HostForLIFE.eu clients are specialized in providing supports for DotNetNuke for many years. We are glad to provide support for European DotNetNuke 7.3.4 hosting users with advices and troubleshooting for our clients website when necessary.

DNN 7.3.4 is a smaller maintenance release than normal and is focused on addressing the most serious platform issues. DNN 7.3.4 addresses a number of platform issues and should be the last release before DNN 7.4.0. DNN 7.3.4 added ability to save localized lists to resource file, added method to remove all subscriptions from a ContentItem, fixed issue where AUM was not correctly handling 301 redirects, Fixed issue where popup iframe is not initialized correctly and fixed issue where multiple region/country controls in a profile did not work correctly.

DotNetNuke 7.3.4 will be a great content management system that support many advance website features such as blogs, forums, e-commerce system, photo galleries and more. DotNetNuke 7.3.4 is a great platform to build your web presence with. HostForLIFE.eu can help customize any web software that company wishes to utilize.

Further information and the full range of features DotNetNuke 7.3.4 Hosting can be viewed here http://www.hostforlife.eu/European-DotNetNuke-734-Hosting

About Company
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. HostForLIFE.eu deliver on-demand hosting solutions including shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see http://www.asp.net/hosting/hostingprovider/details/953). Our service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries.



ASP.NET 5 Hosting France - HostForLIFE.eu :: Develop a Captcha Image Generator in ASP.NET

clock December 19, 2014 05:38 by author Peter

In this tutorial, I will explain you how to Develop a Captcha Image Generator in ASP.NET 5 with C# or VB.NET. CAPTCHA stands for "Completely Automated Public Turing test to tell Computers and Humans Apart".  And here is the code that I use to generate take one .aspx page as GenerateCaptcha.aspx :

GenerateCaptcha.aspx.cs:
using System.IO;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public partial class GenerateCaptcha : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Clear();
        int height = 40;
        int width = 110;
        Bitmap bmp = new Bitmap(width, height);
        RectangleF rectf = new RectangleF(12, 6, 0, 0);
        Graphics g = Graphics.FromImage(bmp);
        g.Clear(Color.White);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.InterpolationMode = InterpolationMode.HighQualityBicubic;
        g.PixelOffsetMode = PixelOffsetMode.HighQuality;
        g.DrawString(Session["captcha"].ToString(), new Font("Cambria", 13, FontStyle.Bold), Brushes.Red, rectf);
        g.DrawRectangle(new Pen(Color.Green), 1, 1, width - 15, height -10);
        g.Flush();
        Response.ContentType = "image/jpeg";
        bmp.Save(Response.OutputStream, ImageFormat.Jpeg);
        g.Dispose();
        bmp.Dispose();
    }
}

Take .aspx where you want to use captcha.
UseCaptcha.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Create your own captcha image generator in ASP.NET using C#.NET/VB.NET</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table>
                    <tr>
                        <td style="height: 50px; width: 100px;">
                            <asp:Image ID="imgCaptcha" runat="server" />
                        </td>
                        <td valign="middle">
                            <asp:Button ID="btnRefresh" runat="server" Text="Refresh" OnClick="btnRefresh_Click" />
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
        </asp:UpdatePanel>
        Enter Captcha:
        <asp:TextBox ID="txtCaptcha" runat="server"></asp:TextBox><br />
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
    </div>
    </form>
</body>
</html>

UseCaptcha.aspx.cs
using System.Text;
using System.Drawing.Imaging;
public partial class UseCaptcha : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            FillCaptcha();
        }
    }
    void FillCaptcha()
    {
        try
            Random random = new Random();
            string combination = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
            StringBuilder captcha = new StringBuilder();
            for (int i = 0; i < 6; i++)
                captcha.Append(combination[random.Next(combination.Length)]);
            Session["captcha"] = captcha.ToString();
            imgCaptcha.ImageUrl = "GenerateCaptcha.aspx";
        }
        catch
        {
            throw;
        }
    }
    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        FillCaptcha();
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (Session["captcha"].ToString() != txtCaptcha.Text)
            Response.Write("Enter Valid Captcha Code");      
        FillCaptcha();
    }
}

And this is the result from the code:



HostForLIFE.eu Proudly Launches of WordPress 4.0.1 Hosting

clock December 15, 2014 07:55 by author Peter

European leading web hosting provider, HostForLIFE.eu announced the support for WordPress 4.0.1 hosting plan due to high demand of WordPress 4.0.1 users in Europe. HostForLIFE.eu is a popular online WordPress hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering fast, fully-managed and secured services in the competitive market.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (France) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customer can start hosting our Wordpress 4.0.1 site on our environment from as just low €3.00/month only.

WordPress 4.0.1 patches a critical cross-site scripting vulnerability affecting comment boxes on websites running the content management system software. An attacker would need only to inject malicious JavaScript into a comment that would infect a reader viewing it on the webpage or an admin in the management dashboard.

The update also addresses three other cross-site scripting vulnerabilities, a cross-side request forgery flaw, a denial-of-service bug related to password checks, server-side request forgery issues, and what WordPress called “an extremely unlikely hash collision” that could lead to account compromise. WordPress said it also invalidates links in a password reset email if the user remembers our password and logs in and changes our email address.

WordPress 4.0.1 addresses an additional eight security issues, including three other XSS vulnerabilities that can be exploited by a contributor or an author, a cross-site request forgery (CSRF) that can be leveraged to trick a user into changing his/her password, and a denial-of-service (DoS) bug.

HostForLIFE.eu is a popular online Windows based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market. Our powerful servers are specially optimized and ensure WordPress 4.0.1 performance.

For more information about this new product, please visit http://hostforlife.eu/European-WordPress-401-Hosting

About us:
HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see http://www.asp.net/hosting/hostingprovider/details/953). Our service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries. Besides this award, we have also won several awards from reputable organizations in the hosting industry and the detail can be found on our official website.



ASP.NET 5 Hosting Italy - HostForLIFE.eu :: Using ValidationSummary Control in ASP.NET

clock December 15, 2014 06:01 by author Peter

Today, I will show you how to ValidationSummary Control in ASP.NET 5. ValidationSummary control allow us to display summary of all validation errors. We can display validation errors summary inline of a web page or a message box or both by using ShowMessageBox and ShowSummary property value true or false.

ValidationSummary will display validation messages as bulleted list, 1 paragraph or only list based on DisplayMode. we can set a header text for validation summar. ASP.NET validationsummary control have many properties to design the error messages text as like fore color, back color, border color, border style, border width, theme, skin and after all CSS class.

This ValidationSummary, allow to summarize of all validation error messages from all validators in a single location. This code below will show you how can we display all validation error messages as summary using ValidationSummary control. In this example, I used three text box and make them required field using requiredfieldvalidator control. When user submit form without entering textboxes value, they got a validation error messages summary in one location as bulleted list.

And here is the example ValidationSummaryExample.aspx code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
    protected void Button1_Click(object sender, System.EventArgs e) {
        Label1.Text = "Your Country: " +
            TextBox1.Text.ToString() +
            "<br />Region: " +
            TextBox2.Text.ToString() +
            "<br />City: " +
            TextBox3.Text.ToString();
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ValidationSummary example: how to use ValidationSummary control in asp.net</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Font-Size="Large" ForeColor="BlueViolet"></asp:Label>
        <br /><br />
        <asp:Label ID="Label2" runat="server" Text="Country Name" AssociatedControlID="TextBox1"></asp:Label>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator
             ID="RequiredFieldValidator1"
             runat="server"
             ControlToValidate="TextBox1"
             ErrorMessage='Input Country!'
             EnableClientScript="true"
             SetFocusOnError="true"
             Text="*"
             >
        </asp:RequiredFieldValidator>
        <br />
        <asp:Label ID="Label3" runat="server" Text="Region Name" AssociatedControlID="TextBox2"></asp:Label>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator
             ID="RequiredFieldValidator2"
             runat="server"
             ControlToValidate="TextBox2"
             ErrorMessage='Input Region!'
             EnableClientScript="true"
             SetFocusOnError="true"
             Text="*"
             >
        </asp:RequiredFieldValidator>
        <br />       
        <asp:Label ID="Label4" runat="server" Text="City Name" AssociatedControlID="TextBox3"></asp:Label>
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator
             ID="RequiredFieldValidator3"
             runat="server"
             ControlToValidate="TextBox3"
            ErrorMessage='Input Region!'
            EnableClientScript="true"
            SetFocusOnError="true"
             Text="*"
             >
        </asp:RequiredFieldValidator>
        <br />
        <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />
       <br /><br />
        <asp:ValidationSummary ID="ValidationSummary1" runat="server" HeaderText="Following error occurs:" ShowMessageBox="false" DisplayMode="BulletList" ShowSummary="true" />
    </div>
    </form>
</body>
</html>



HostForLIFE.eu Proudly Launches ASP.NET 5 Hosting

clock December 8, 2014 10:06 by author Peter

European leading web hosting provider, HostForLIFE.eu announces the launch of ASP.NET 5  support on the recently released Windows Server 2012 R2.

HostForLIFE.eu was established to cater to an under served market in the hosting industry; web hosting for customers who want excellent service. HostForLIFE.eu – a cheap, constant uptime, excellent customer service, quality, and also reliable hosting provider in advanced Windows and ASP.NET technology. HostForLIFE.eu proudly announces the availability of the ASP.NET 5 hosting in our entire servers environment.

ASP.NET is Microsoft's dynamic website technology, enabling developers to create data-driven websites using the .NET platform and the latest version is 5 with lots of awesome features. ASP.NET 5 is a lean .NET stack for building modern web apps. Microsoft built it from the ground up to provide an optimized development framework for apps that are either deployed to the cloud or run on-premises. It consists of modular components with minimal overhead.

According to Microsoft officials, much of the functionality in the ASP.NET 5 release is a new flexible and cross-platform runtime, a new modular HTTP request pipeline, Cloud-ready environment configuration, Unified programming model that combines MVC, Web API, and Web Pages, Ability to see changes without re-building the project, etc.

HostForLIFE.eu hosts its servers in top class data centers that is located in Amsterdam (NL), London (UK), Paris (FR) and Seattle (US) to guarantee 99.9% network uptime. All data center feature redundancies in network connectivity, power, HVAC, security, and fire suppression. All hosting plans from HostForLIFE.eu include 24×7 support and 30 days money back guarantee. The customers can start hosting our ASP.NET 5 site on our environment from as just low €3.00/month only.

HostForLIFE.eu is a popular online ASP.NET  based hosting service provider catering to those people who face such issues. The company has managed to build a strong client base in a very short period of time. It is known for offering ultra-fast, fully-managed and secured services in the competitive market.

HostForLIFE.eu offers the latest European ASP.NET 5 hosting installation to all our new and existing customers. The customers can simply deploy our ASP.NET 5 website via our world-class Control Panel or conventional FTP tool. HostForLIFE.eu is happy to be offering the most up to date Microsoft services and always had a great appreciation for the products that Microsoft offers.

Further information and the full range of features ASP.NET 5 Hosting can be viewed here http://hostforlife.eu/European-ASPNET-5-Hosting

About Company
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. HostForLIFE.eu deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

HostForLIFE.eu is awarded Top No#1 SPOTLIGHT Recommended Hosting Partner by Microsoft (see http://www.asp.net/hosting/hostingprovider/details/953). Their service is ranked the highest top #1 spot in several European countries, such as: Germany, Italy, Netherlands, France, Belgium, United Kingdom, Sweden, Finland, Switzerland and other European countries. Besides this award, we have also won several awards from reputable organizations in the hosting industry and the detail can be found on our official website.



ASP.NET 5 Hosting - HostForLIFE.eu :: Auto Resize Text Box in ASP.NET

clock December 5, 2014 06:53 by author Peter

In this article, we want to talk about How to to develop a simple Example of text box control with ASP.NET 5. Once we enter data during this text box control we want to the length (re-size height and width) of text box. Text box is an ASP.NET web control, use for obtaining input by user as similar to the login web site we see username and password Textbox exactly in which we enter username and password. Inside the Toolbox we obtain a textbox only drag and drop it on ASP.NET web site and then it is automatically create our html code. We think about a text box and attempt to Auto re-size it once we enter value in text box.

And this is the example code that I used:
JavaScript function for resize ASP.NET control
And here is the Text Box auto resize function.

function resizemultilineTextBox(txt) {
            txt.style.height = "1px";
            txt.style.height = (1 + txt.scrollHeight) + "px";
        }
Asp.net web page code with Textbox:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Autoresizetextboxcontrol.aspx.cs" Inherits="Autoresizetextboxcontrol" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
        <script>
        function resizemultilineTextBox(txt) {
            txt.style.height = "1px";
            txt.style.height = (1 + txt.scrollHeight) + "px";
        }
    </script>
    <style type="text/css">
        .style1
        {
            color: #990000;
            text-decoration: underline;
            font-family: Arial, Helvetica, sans-serif;
        }
    </style>
</head>
<body>
    <form id="form2" runat="server">
        <div align="center" style="height: 123px; background-color: #6699FF">
        <h1 class="style1">Auto Resize ASP.NET TextBox Control</h1>
            <table style="width: 494px">
                <tr>
                    <td>Enter Text Here: </td>
                    <td>                      
                        <asp:TextBox ID="txtDescription" runat="server"                            

onkeyup="resizemultilineTextBox(this)" TextMode="MultiLine" Width="212px">
</asp:TextBox>                      
                    </td>
                </tr>
            </table>
        </div>
    </form>
</body>
</html>



ASP.NET 5 Hosting - HostForLIFE.eu :: How to create “Remember Me” Login Page using checkbox with ASP.NET ?

clock December 1, 2014 06:12 by author Peter

In this tutorial, I will tell you How to create “Remember Me” Login Page using checkbox with ASP.NET 5 and C#. Whenever you tick Remember Me checkbox it will maintain username and password for web site user using Cookies.

When user click login button that could stores the username and password inside the cookie. First thing you need to do is confirm that the Remember Me checkbox is checked or not, if it's checked then store the username and password inside the cookie to the 1 month and if not checked then set the expiration day to 1 day in else condition to destroy the cookie.

And here is the code that I used:

protected void Page_Load(object sender, EventArgs e)  

      if (!Page.IsPostBack) 
      { 
           if (Request.Cookies["UserName"] != null) 
                txtUserName.Text = Request.Cookies["UserName"].Value; 
           if (Request.Cookies["Password"] != null) 
                txtPassword.Text = Request.Cookies["Password"].Value; 
           if (Request.Cookies["UserName"] != null && Request.Cookies["Password"] != null) 
                chkRember.Checked = true;  
      }  
}  
protected void btnLogin_Click(object sender, EventArgs e) 
 { 
       string stringconnection = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; 
       MySqlConnection connection = new MySqlConnection(stringconnection); 
      try 
      {  
           int flag = 0; 
           if (chkRember.Checked == true) 
           { 
                Response.Cookies["UserName"].Value = txtUserName.Text; 
                Response.Cookies["Password"].Value = txtPassword.Text; 
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(1); 
                Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(1); 
           } 
           else 
           { 
                Response.Cookies["UserName"].Expires = DateTime.Now.AddMonths(-1); 
                Response.Cookies["Password"].Expires = DateTime.Now.AddMonths(-1); 
           }  
           MySqlCommand com = new MySqlCommand("select * from tbl_user_details", connection); 
           connection.Open(); 
           if (connection.State == ConnectionState.Open) 
           { 
                MySqlDataReader objSqlDataReader;                
                objSqlDataReader = com.ExecuteReader();

                    while (objSqlDataReader.Read())                 
                     { 
                     if (objSqlDataReader[2].ToString().Equals(txtUserName.Text) && objSqlDataReader[5].ToString().Equals(txtPassword.Text)) 
                     { 
                          flag = 1; 
                          Session["UserName"] = txtUserName.Text; 
                          Session["UserType"] = objSqlDataReader[8].ToString(); 
                          Response.Redirect("ContactUs.aspx", false); 
                     } 
                     else 
                     { 
                          ClientScript.RegisterStartupScript(Page.GetType(), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>"); 
                    } 
                } 
           } 
      } 
      catch (Exception ex) 
      { 
           lblMsg.Text = ex.ToString(); 
      } 
      finally  
      { 
           connection.Close(); 
      }
 }



UK ASP.NET 4.5.2 Hosting - HostForLIFE.eu :: How to Use NServiceBus with ASP.NET SignalR ?

clock November 24, 2014 06:35 by author Peter

In this tutorial, I will tell you how to use NServiceBus with ASP.NET SignalR. In detail right listed below what I'm planning to do is periodically publish an event utilizing NServiceBus. I will be able to use a ASP.NET MVC application as my front end and there I will be able to use a an additional NServiceBus client and that is liable for capturing event broadcasted from the NServiceBus publisher. Then working with ASP.NET SignalR, I will certainly be updating the UI with others captured events content.

First, Add a new ASP. NET MVC application to the solution.

Currently I'm running NServiceBus. Host and Microsoft ASP. NET SignalR nuget packages on ASP. NET MVC project using Package Manager Console. NServiceBus. Host can add the EndpointConfig. cs towards the project and I'm keeping as it's. Currently I'm making a folder named “SignalR” within my project and I'm heading to add a brand new category there named “EventMessageHandler”.
public class EventMessageHandler : IHandleMessages<MyMessage>
{
    public void Handle(MyMessage message)
    { 
    }
}

When the NServiceBus has revealed an event of kind “MyMessage”, “Handle” method in “EventMessageHandler” class can tackle it. For the moment, lets maintain the “Handle” method empty and let’s add a OWIN Startup class towards the project by right clicking upon the App_Start folder and selecting a OWIN Startup class template.

Next step, I am modifying the created OWIN Startup class with these code:
using Owin;
using Microsoft.Owin;
using NServiceBus; 
[assembly: OwinStartup(typeof(NServiceBusSignalRSample.Startup))]
namespace NServiceBusSignalRSample
{
    public class Startup
    {
        public static IBus Bus { get; private set; } 
        public static void Configuration(IAppBuilder app)
        {
            Bus = Configure
                    .With()
                    .DefaultBuilder()
                    .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("NServiceBusSignalRSample.Messages"))
                    .PurgeOnStartup(false)
                    .UnicastBus()
                    .LoadMessageHandlers()
                    .CreateBus()
                    .Start(); 
            app.MapSignalR();
        }
    }
}


Right listed below I've configured my NServiceBus host and I'm mapping SignalR hubs towards the app builder pipeline. Next action is to make a SignalR hub. For the I'm adding the listed class towards the previously produced “SignalR” folder.

public class MyHub : Hub{
    public void Send(string name, string message)
    {
        Clients.All.addNewMessageToPage(name, message);
    }
}

Currently right listed below I'm deriving “MyHub” class from “Hub” and I ve got a method there named “Send” that takes 2 parameters. Within the method, I'm calling the consumer aspect “addNewMessageToPage” that still I haven’t wrote.

Just before starting off using the client aspect code, let’s modify the “Handle” method in “EventMessageHandler” class now to call my hubs’ send method.
public class EventMessageHandler : IHandleMessages<MyMessage>
{
    public void Handle(MyMessage message)
    {
        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
        hubContext.Clients.All.addNewMessageToPage(message.Message, "Peter");
    }
}

Next,  I'm ready along with the back end code. Final thing to become done is to make a view in client side, initiate the hub connection and build a method named “addNewMessageToPage”. For the first I'm modifying the “HomeController” and adding a brand new Action there named “SignalR”.
public ActionResult SignalR()
{
    return View();
}

Then I'm correct clicking upon the Motion and making a new view along with a similar name “SignalR”. I'm modifying the “SignalR” view as follows.
@{
    ViewBag.Title = "SignalR";
}
<h2>SignalR</h2> 
<div class="container">
    <ul id="output"></ul>
</div> 
@section scripts {
    <script src="~/Scripts/jquery.signalR-2.1.1.min.js"></script>
    <script src="~/signalr/hubs"></script>
     <script>       
       $(function () {
            $.connection.hub.logging = true;
            $.connection.hub.start();
            var chat = $.connection.myHub; 
            chat.client.addNewMessageToPage = function (message, name) {
$('#output').append('<li>' + message + ' ' + name + '</li>');          
 };
        });
    </script>
}

Now I'm ready. One last factor to become done is to line multiple startup projects.

Finally, I'm running the Apps. Hope this post works for you!



About HostForLIFE

HostForLIFE is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2019 Hosting, ASP.NET 5 Hosting, ASP.NET MVC 6 Hosting and SQL 2019 Hosting.


Month List

Tag cloud

Sign in