ASP.NET 4.5 and ASP.NET Core 1 Hosting BLOG

Tutorial and Articles about ASP.NET 4.0 and the latest ASP.NET 4.5 Hosting

ASPHostPortal.com Announces ASP.NET Core RTM Hosting Solution

clock July 26, 2016 21:57 by author Dan

ASPHostPortal.com is set up with an aim to serve customers in an excellent manner by providing them quality service. They strongly believe in high quality standards and hence, you’ll always find their services better than every other host in this industry. They understand the value of time and hence their ordering process is very simple. Customers can choose servers from multiple price levels to suit their business model. Today, they offer ASP.NET Core RTM host with expert team support.

ASP.NET is an acronym for the Active Server Pages. NET, is a brilliant framework developed by Microsoft. ASP.NET is extremely useful for creation of web applications, and web pages, and forms an essential part of the web goodies developed for any online content. ASP.NET not only facilitates usage of scripting languages, but also allows you to incorporate usage of extremely efficient next-generation programming languages like Java, VB, C+and the likes of them.

Looking at the historical perspective, in the earlier days, the development of well-designed webpages were a tedious task, and the developers had to put in rigorous efforts due to lack of efficient technology and a complete framework. As a result, soon after the release of IIS, a powerful technology like ASP.NET was in high demand for developing proficient web-based applications within a short time without putting-in too much of human labor.

ASPHostPortal.com offers ASP.NET Core RTM Hosting with expert team support. They support this new technology with affordable price, a lot of ASP.NET features, 99.99% uptime guarantee, 24/7 support, and 30 days money back guarantee. They strive to make sure that all customers have the finest web-hosting experience as possible. To learn more about their ASP.NET Core RTM Hosting, please visit http://asphostportal.com/ASPNET-Core-1-0-Hosting

About ASPHostPortal.com:

ASPHostPortal.com is The Best, Cheap and Recommended ASP.NET & Linux Hosting. ASPHostPortal.com has ability to support the latest Microsoft, ASP.NET, and Linux technology, such as: such as: WebMatrix, Web Deploy, Visual Studio, Latest ASP.NET Version, Latest ASP.NET MVC Version, Silverlight and Visual Studio Light Switch, Latest MySql version, Latest PHPMyAdmin, Support PHP, etc. Their service includes shared hosting, reseller hosting, and Sharepoint hosting, with speciality in ASP.NET, SQL Server, and Linux solutions. Protection, trustworthiness, and performance are at the core of hosting operations to make certain every website and software hosted is so secured and performs at the best possible level.



ASP.NET Hosting - ASPHostPortal.com :: Tips To Use BackgroundWorker in C#

clock July 26, 2016 19:54 by author Armend

How To Use BackgroundWorker in C#

BackgroundWorker is the class in System.ComponentModel which is used when you need to do some task on the back-end or in different thread while keeping the UI available to users (not freezing the user) and at the same time, reporting the progress of the same.

Using the Code

Backgroundworker has three event handlers which basically takes care of everything one needs to make it work.

  • DoWork - Your actual background work goes in here
  • ProgressChanged - When there is a progress in the background work
  • RunWorkerCompleted - Gets called when background worker has completed the work.

I have created a sample WPF application which demonstrates how to use the background worker in C#.

<ProgressBar x:Name="progressbar"
 HorizontalAlignment="Left" Height="14"
 Margin="191,74,0,0" VerticalAlignment="Top"
 Width="133"/>
<Button x:Name="button" Content="Button"
 HorizontalAlignment="Left"
 Margin="249,97,0,0" VerticalAlignment="Top"
 Width="75" Click="button_Click"/>

On Window initialization, I am creating a new object of BackgroundWorker and registering the event handlers for the same.

BackgroundWorker bg;
public MainWindow()
{
InitializeComponent();
bg = new BackgroundWorker();
bg.DoWork += Bg_DoWork;
bg.ProgressChanged += Bg_ProgressChanged;
bg.RunWorkerCompleted += Bg_RunWorkerCompleted;
bg.WorkerReportsProgress = true;
}

Here is the implementation of all three event handlers.

private void Bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
MessageBox.Show("Task completed");
}
private void Bg_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
progressbar.Value += 1;
//label.Content = e.ProgressPercentage;
}
private void Bg_DoWork(object sender, DoWorkEventArgs e)
{
for (int i = 1; i &amp;lt;= 10; i++)
{
Thread.Sleep(1000); //do some task
bg.ReportProgress(0);
}
}

In order to make this stuff work, you need to trigger the DoWork event and for that, I am using button click event.

private void button_Click(object sender, RoutedEventArgs e)
   {
           progressbar.Value = 0;
           progressbar.Maximum = 10;
           bg.RunWorkerAsync();
   }

It is a very basic example of background worker, but it is good to start with. One must be wondering how it is updating the progress bar if it is working in the background.
Well, the ProgressChanged event handler runs on UI thread whereas DoWork runs on application thread pool. That's why despite running in the background on different thread, it is not freezing the UI and updating the progressbar upon making progress.

 

Best ASP.NET Core 1.0 Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.

 



ASP.NET Core 1.0 Hosting - ASPHostPortal.com :: Easy Steps to Add Numeric String in ASP.NET

clock July 25, 2016 20:20 by author Dan

Must Know Issue: Basics of String Format in .Net

Numeric Format

double dValue = 55000.54987D;

//displaying number in different formats

Response.Write("Currency Format: " + dValue.ToString("C") + "
");

Response.Write("Scientific Format: " + dValue.ToString("E") + "
");

Response.Write("Percentage Format: " + dValue.ToString("P") + "
");

/* OUTPUT */

Currency Format: $55,000.55
Scientific Format: 5.500055E+004
Percentage Format: 5,500,054.99 %

Getting Culture Specific String


double dValue = 55000.54987D;

//You can Remove this line

Thread.CurrentThread.CurrentCulture = new CultureInfo("de-DE");

//This line will automatically detect client culture

//and display data accordingly

//Here culture has forcefully changed to german to

//view difference in output

CultureInfo ci = Thread.CurrentThread.CurrentCulture;

//displaying number in different formats

Response.Write("Currency Format: " + dValue.ToString("C",ci) + "
");

Response.Write("Scientific Format: " + dValue.ToString("E",ci) + "
");

Response.Write("Percentage Format: " + dValue.ToString("P",ci) + "
");

/* OUTPUT */

Currency Format: 55.000,55 €
Scientific Format: 5,500055E+004
Percentage Format: 5.500.054,99%

Best ASP.NET Core 1.0 Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASP.NET Core 1.0 Hosting - ASPHostPortal.com :: Easy Steps to avoid multiple database request in ASP.NET

clock July 22, 2016 20:09 by author Dan

It is not good to execute multiple db request for loading single page.  Review your database code to see if you have request paths that go to the database more than once. Each of those round-trips decreases the number of requests per second your application can serve. By returning multiple resultsets in a single database request, you can cut the total time spent communicating with the database.

In order to improve performance you should execute single stored proc and bring multiple resultset in to single db request.  In this article i will explain you how to avoid multiple database request and how to bring multiple resultset into single db request.

Consider a scenario of loading a Product Page, which displays

  • Product Information and
  • Product Review Information

In order to bring 2 database request in single db request, your sql server stored proc should be declared as below.

SQL Server Stored Proc

CREATE PROCEDURE GetProductDetails
 @ProductId bigint,
AS
SET NOCOUNT ON

--Product Information
Select ProductId,
 ProductName,
 ProductImage,
 Description,
 Price
From Product
Where ProductId = @ProductId


--Product Review Information
Select  ReviewerName,
 ReviewDesc,
 ReviewDate
From ProductReview
Where ProductId = @ProductId


Asp.net, C# Code to bring multiple db request into single db request

Code Inside Data Access Class Library (DAL)


public DataSet GetProductDetails()
{
SqlCommand cmdToExecute = new SqlCommand();
cmdToExecute.CommandText = "GetProductDetails";
cmdToExecute.CommandType = CommandType.StoredProcedure;
DataSet dsResultSet = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter(cmdToExecute);

try
{
    var conString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnStr"];
    string strConnString = conString.ConnectionString;
    SqlConnection conn = new SqlConnection(strConnString);

    cmdToExecute.Connection = conn;

    cmdToExecute.Parameters.Add(new SqlParameter("@ ProductId", SqlDbType.BigInt, 8, ParameterDirection.Input, false, 19, 0, "", DataRowVersion.Proposed, _productId));

    //Open Connection
    conn.Open();

    // Assign proper name to multiple table
    adapter.TableMappings.Add("Table", "ProductInfo");
    adapter.TableMappings.Add("Table1", "ProductReviewInfo");
    adapter.Fill(dsResultSet);

    return dsResultSet;             
}
catch (Exception ex)
{
    // some error occured.
    throw new Exception("DB Request error.", ex);
}
finally
{
    conn.Close();
    cmdToExecute.Dispose();
    adapter.Dispose();
}
}



Code Inside Asp.net .aspx.cs page

protected void Page_Load(object sender, EventArgs e)
{
   if (Request.QueryString[ProductId] != null)
   {
      long ProductId = Convert.ToInt64(Request.QueryString[ProductId].ToString()); 
  
      DataSet dsData = new DataSet();

      //Assuming you have Product class in DAL
      ProductInfo objProduct = new ProductInfo();
      objProduct.ProductId = ProductId;
      dsData = objProduct.GetProductDetails();

      DataTable dtProductInfo = dsData.Tables["ProductInfo"];
      DataTable dtProductReviews = dsData.Tables["ProductReviewInfo"];

      //Now you have data table containing information
      //Make necessary assignment to controls
      .....
      .....
      .....
      .....
      ..... 

    }
}



Hope above code gave you basic idea of why it is important to avoid multiple db request and how to bring multiple recordset with single db request.

Best ASP.NET Core 1.0 Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASP.NET Hosting - ASPHostPortal.com :: Tips To Set Up Custom Error Pages In IIS 7.5 With ASP.NET

clock July 13, 2016 23:25 by author Armend

Tips To Set Up Custom Error Pages In IIS 7.5 With ASP.NET

If we configure .NET Error Pages at the site level, ASP.NET stores the settings in the site’s web.config file. Since these settings are stored in the web.config file they are portable and can be easily moved to another server with the site’s content.

How to setup Custom Error Pages in IIS 7.5

Open Internet Information Services (IIS) Manager.  Select your website. Note: This could also be set at the server level and applied to all sites on the server. DoubleClick on the “.NET Error Pages” icon.

The .NET Error Pages features view will be displayed.

Click the “Edit Feature Settings” link to enable this feature. The “Edit Error Page Settings” dialog box will appear.

In order to change the default mode, we must also specify a “Default Page”. This page will be used for all status codes that are  not otherwise defined. In our example we are using a generic custom error page to trap all other errors. Once you enter the absolute URL for the default error page click OK.  Note:  It may be a good idea to use a static

HTML page here just in case ASP.NET is not functioning properly.
By default server errors are shown when logged on locally to the IIS server and custom errors will only be used from remote sessions. We will want to change this to “On” if we are logged on locally to the IIS server. Otherwise, it will display detailed server errors, and not our custom error pages.

Next we will explicitly define the 404 Error code.

To get the browser to throw a 404 error, we pointed it to a file on the test site that does not exist. As you can see in the following image the friendly HTTP 404 error page was shown in IE9.
A friendly HTTP 404 Error in IE9:

On the .NET Error Pages Actions menu click the Add link.

The “Add Custom Error Page” dialog will appear. This is where we define individual error pages per status code. For our example we will add a custom page for the HTTP 404 Error.

Now that we have turned on the feature and added a custom page for the 404 status code we can verify it is working. To verify visit a page that does not exist. In our example we will use http://mysite.com/deletedfile.aspx. You can see in the following image that the custom error page was shown.
Our custom 404 Error message in IE 9

As mentioned above this can also be managed from the site’s web.config file. Consider the following configuration section from our site’s web.config file.

<configuration>
  <system.web>
    <customErrors defaultRedirect=”http://mysite.com/errors/Error.aspx” mode=”RemoteOnly”>
       <error redirect=”http://mysite.com/errors/404.aspx” statusCode=”404″ />
    </customErrors>
  </system.web>
</configuration>

Everything we set in the GUI can easily be set directly in the web.config. This will also allow you to setup .NET Error Pages, if you are on a shared hosting Plan. Here at ASPHostPortal.com, our shared, dedicated and Windows cloud server hosting plans can all benefit from using custom .NET Error Pages.




ASP.NET Core 1.0 Hosting - ASPHostPortal.com :: Easy Steps to Create FileUpload Control With Drag Drop And Progress Bar in ASP.NET

clock July 1, 2016 19:50 by author Dan

This Example explains how to use AjaxFileUpload Control With Drag Drop And Progress Bar Functionality In Asp.Net 2.0 3.5 4.0 C# And VB.NET. May 2012 release of AjaxControlToolkit includes a new AjaxFileUpload Control which supports Multiple File Upload, Progress Bar and Drag And Drop functionality. These new features are supported by Google Chrome version 16+, Firefox 8+ , Safari 5+ and Internet explorer 10 + , IE9 or earlier does not support this feature. AjaxFileUpload Control Example with Drag Drop And Progress Bar.

To start with it, download and put latest AjaxControlToolkit.dll in Bin folder of application, Place ToolkitScriptManager and AjaxFileUpload on the page.

HTML SOURCE

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"/>


<asp:AjaxFileUpload ID="AjaxFileUpload1" runat="server"

                    OnUploadComplete="UploadComplete"

                    ThrobberID="loader"/>


<asp:Image ID="loader" runat="server"

           ImageUrl ="~/loading.gif" Style="display:None"/>


ThrobberID is used to display loading image instead of progress bar in unsupported browsers. Type of files uploaded can be restricted by using AllowedFileTypes property with comma separated list such as "zip,doc,pdf".

Write following code in OnUploadComplete event to save the file.

C#

protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
{
 string path = Server.MapPath("~/Uploads/") + e.FileName;
 AjaxFileUpload1.SaveAs(path);
}


VB.NET

protected void UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e)
 {
string path = Server.MapPath("~/Uploads/") + e.FileName;
 AjaxFileUpload1.SaveAs(path);
}


Build and run the code.

Best ASP.NET Core 1.0 Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASPHostPortal.com Announces WordPress 4.5.3 Hosting Solution

clock June 28, 2016 23:06 by author Dan

ASPHostPortal.com is trusted web hosting provider since 2008. We strongly believe in high quality standards and hence, you’ll always find our services better than every other host in this industry. We understand the value of time and hence our ordering process is very simple. Customers can choose servers from multiple price levels to suit their business model. Today, we offer premium WordPress 4.5.3 hosting with fast speed, and uptime guarantee.

WordPress has grown into what would be called a content management system, or CMS. A CMS is a tool to store all of the information required for your website and present it to your visitors in a professional, organized way. Other content management systems include Joomla and Drupal, but the reality is that WordPress is the easiest to understand, the easiest to work with, and the most easily adaptable.

WordPress makes creating, editing and organising your content simple and, as a result, less time-consuming. That gives you more time to focus on other areas of your business. WordPress also gives you the chance to get a professional design to make your website look great - often free of charge.

The best way to see how WordPress streamlines setting up your website is to try it for yourself. WordPress is easy to install on your web hosting or, if you sign up on the WordPress website, you can explore its features with no set-up required.

ASPHostPortal.com provides Premium WordPress 4.5.3 Hosting plans on high performance servers and high-speed internet connection in the world. Every server is equipped with at least 2x Intel Xeon Quad-Core processors and massive amounts of memory. We are using SSD's for storage, which provides much higher performance in terms of I/O and data transfer speed. The servers are connected to the network using multiple 1Gbps ports (bond network). To learn more about their WordPress 4.5.3 Hosting, please visit http://asphostportal.com/WordPress-Hosting

About ASPHostPortal.com:

ASPHostPortal.com is The Best, Cheap and Recommended ASP.NET & Linux Hosting. ASPHostPortal.com has ability to support the latest Microsoft, ASP.NET, and Linux technology, such as: such as: WebMatrix, Web Deploy, Visual Studio, Latest ASP.NET Version, Latest ASP.NET MVC Version, Silverlight and Visual Studio Light Switch, Latest MySql version, Latest PHPMyAdmin, Support PHP, etc. Their service includes shared hosting, reseller hosting, and Sharepoint hosting, with speciality in ASP.NET, SQL Server, and Linux solutions. Protection, trustworthiness, and performance are at the core of hosting operations to make certain every website and software hosted is so secured and performs at the best possible level.



ASP.NET Hosting - ASPHostPortal.com :: Dependency Injection In ASP.NET Core

clock June 28, 2016 20:19 by author Armend

This article explains the dependency injection feature available out of the box in ASP.NET core (ASP.NET 5). It will also cover some of the basics of dependency injection so that everyone can get the most out this article.

What is dependency Injection

Dependency Injection is the process of “injecting” the “dependency” whenever the dependency is requested by a client, where the dependency may be another service which the client (requester) may have no means of knowing how to create.

As an analogy, imagine a person (client) going to office carrying his lunch cooked by himself. In this scenario, the person has a “dependency” on food. But he had to know how to cook his food. But honestly, not everyone (client) knows to cook, but people do need food (dependency). This is where restaurants play the role of dependency Injection. They can supply food (“inject dependency”) to the people (client) without the person (client) needing to know how to cook.

This is also called as Inversion of control. Since the control for creation of the service has been passed from the requester to another entity which takes care of creating the dependencies needed by a class to perform its tasks. The entity which takes care of creating these requested dependencies and injecting them automatically to the client is known as the DI (dependency Injection) container.

Dependency Injection in ASP.NET Core

Ok, enough said about what dependency injection is. I am sure most of you knew it. If not, this is a great feature to know and a great tool to add to your tool belt! Let us now look at how to implement dependency injection out of the box in ASP.NET core.
ASP.NET core applications can leverage built in framework support for implementing dependency injection. It has support for the following types of lifetimes for configured services (injected dependencies).

  •     Transient – A new instance of the service is created each time it is requested. It can be used for stateless and light weight services.
  •     Scoped – A single instance is created once per request.
  •     Singleton – Created only once the first time they are requested.

Now for some code!

Use case

Implement a UniqueKeyProvider service. For demonstrating the lifetimes, we will create three differently named interfaces (one for each type of lifetime) for UniqueKeyprovider, all inheriting from the same parent interface having a single property, UniqueKey.
Also, to further illustrate the scoped and singleton lifetime, we will create another service, SomeService, which will have a dependency on all the three different UniqueKeyProvider services (the three different lifetime services).

1. Service Interface definition

Please note the three differently named interfaces, one for demonstrating each type of lifetime. 

namespace DependencyInjectionASPNetCore.Services 
    { 
        public interface IUniqueKeyProvider 
        { 
            Guid UniqueKey 
            { 
                get; 
                set; 
            } 
        } 
        public interface ITransientUniqueKeyProvider: IUniqueKeyProvider 
        {} 
        public interface IScopedUniqueKeyProvider: IUniqueKeyProvider 
        {} 
        public interface ISingletonUniqueKeyProvider: IUniqueKeyProvider 
        {} 
    } 

2. Service Class definition

    namespace DependencyInjectionASPNetCore.Services 
    { 
        public class UniqueKeyProvider: ITransientUniqueKeyProvider, 
        ISingletonUniqueKeyProvider, 
        IScopedUniqueKeyProvider 
        { 
            public Guid UniqueKey 
            { 
                get; 
                set; 
            } 
            public UniqueKeyProvider(Guid uniqueKey) 
            { 
                UniqueKey = uniqueKey; 
            } 
        } 
    } 

3. Registering the services in the startup.cs

Now register your services in the startup.cs file. This is the step where you are actually configuring your dependency injection container. You are basically instructing your dependency injection container that if the user requests for the service, ITransientUniqueKeyProvider, then please provide with a transient scoped instance of UniqueKeyProviderclass and similarly for the other services.
You need to register your services in the ConfigureServices method in the startup.cs file. Please refer to the code below for registration,

   

    services.AddTransient<ITransientUniqueKeyProvider>(provider =>newUniqueKeyProvider(Guid.NewGuid())); 
    services.AddScoped<IScopedUniqueKeyProvider>(provider =>newUniqueKeyProvider(Guid.NewGuid())); 
    services.AddSingleton<ISingletonUniqueKeyProvider>(provider =>newUniqueKeyProvider(Guid.NewGuid())); 
    services.AddTransient<ISomeService, SomeService>();
 

Note that I am also registering another service, ISomeServicewhich I am just using for demo purposes for showing the nature of transient and singleton lifetime. Also note that SomeService implementation requires dependency on the three Unique Key providers, which will be injected through dependency injection.Implementation of ISomeservice provided below,

4. IsomeService and Someservice Implementation

    public class ISomeService 
    { 
        ITransientUniqueKeyProvider TransientUniquekeyProvider 
        { 
            get; 
            set; 
        } 
        IScopedUniqueKeyProvider ScopedUniquekeyProvider 
        { 
            get; 
            set; 
        } 
        ISingletonUniqueKeyProvider SingletonUniquekeyProvider 
        { 
            get; 
            set; 
        } 
    } 
    public class SomeService: ISomeService 
    { 
        public ITransientUniqueKeyProvider TransientUniquekeyProvider 
        { 
            get; 
            set; 
        } 
        public IScopedUniqueKeyProvider ScopedUniquekeyProvider 
        { 
            get; 
            set; 
        } 
        public ISingletonUniqueKeyProvider SingletonUniquekeyProvider 
        { 
            get; 
            set; 
        } 
        public SomeService(ITransientUniqueKeyProvider transientprovider, 
            IScopedUniqueKeyProvider scopedprovider, 
            ISingletonUniqueKeyProvider singletonprovider) 
        { 
            TransientUniquekeyProvider = transientprovider; 
            ScopedUniquekeyProvider = scopedprovider; 
            SingletonUniquekeyProvider = singletonprovider; 
        } 
    } 

Now it is time to wrap it all up and test it through a controller. I am using the Home controller’s Index action. Please refer to the below code from the controller and view.

5. Home Controller

    public class HomeController: Controller 
    {  
        private ITransientUniqueKeyProvider _transientUniquekeyProvider; 
        private IScopedUniqueKeyProvider _scopedUniquekeyProvider; 
        private ISingletonUniqueKeyProvider _singletonUniquekeyProvider; 
        private ISomeService _someserviceProvider; 
        public HomeController(ITransientUniqueKeyProvider transientprovider, 
            IScopedUniqueKeyProvider scopedprovider, 
            ISingletonUniqueKeyProvider singletonprovider, ISomeService someserviceprovider) 
        { 
            _transientUniquekeyProvider = transientprovider; 
            _scopedUniquekeyProvider = scopedprovider; 
            _singletonUniquekeyProvider = singletonprovider; 
            _someserviceProvider = someserviceprovider; 
        } 
        public IActionResult Index() 
        { 
            ViewBag.transientID = _transientUniquekeyProvider.UniqueKey; 
            ViewBag.scopedID = _scopedUniquekeyProvider.UniqueKey; 
            ViewBag.singletonID = _singletonUniquekeyProvider.UniqueKey; 
            ViewBag.someServiceProvider = _someserviceProvider; 
            return View(); 
        } 
    } 

Note the constructor which takes in the dependencies. So when the request comes to this page, the framework notes that it needs an implementation for these services. It checks the DI container and finds the registration, and based on that the valid instance is passed to the constructor. The same happens in case of the ISomeService dependency which the controller’s constructor needs.

6. Index View

In the view file, we are just displaying the values that we set in the view bag. Results provided in the next section.

<div style="margin-top:35px"> 
lt;pstyle="font-weight:bold;text-decoration:underline"> 
These are the values that were injected into the home controller 
</p> 
<p> 
    Transient value of Guid: @ViewBag.transientID 
</p> 
<p> 
    Scoped value of Guid: @ViewBag.scopedID 
</p> 
<p> 
    Singleton value of Guid: @ViewBag.singletonID 
</p> 
</div> 
 
<div> 
    <p style="font-weight:bold;text-decoration:underline"> 
 
        These are the values that were injected into Someservice Implementation 
        </p> 
        <p> 
            Transient value of Guid: @ViewBag.someServiceProvider.TransientUniquekeyProvider.UniqueKey 
        </p> 
        <p> 
            Scoped value of Guid: @ViewBag.someServiceProvider.ScopedUniquekeyProvider.UniqueKey 
        </p> 
        <p> 
            Singleton value of Guid: @ViewBag.someServiceProvider.SingletonUniquekeyProvider.UniqueKey 
        </p> 
</div>

I really hope it was useful and fun. Happy coding!

 



ASP.NET Core 1.0 Hosting - ASPHostPortal.com :: How to integrate those fancy modal image preview in ASP.NET

clock June 27, 2016 20:51 by author Dan

Today, in this post I will quickly show you " How to integrate those fancy modal image preview in ASP.NET ".
Magic library for this functionality is mighty FancyBox the "tool that offers a nice and elegant way to add zooming functionality for images, html content and multi-media on your webpages. It is built at the top of the popular JavaScript framework jQuery and is both easy to implement and a snap to customize."

Let's see how things are working....

  1. We create web site project inside our VS 2012.
  2. Include into project jQuery in this sample I use latest version 1.7.2.
  3. Also we need to include FancyBox. (It would be very strange to not include it in this sample)

So, our project look's like:

Here you can see our included files inside project, also you can see our test page html and jQuery code.
Most important thing here is that you use class="fancybox" as image control css class.

jQuery code is very very simple as you can see here:

       $(document).ready(function () {
            $(".fancybox").fancybox();
        });


There are more cases in how to use fancybox that you can check at FancyBox.

Effect that we managed to create looks like this:

When we click on image we get this.

So, long, folks!

Best ASP.NET Core 1.0 Hosting Recommendation

ASPHostPortal.com provides its customers with Plesk Panel, one of the most popular and stable control panels for Windows hosting, as free. You could also see the latest .NET framework, a crazy amount of functionality as well as Large disk space, bandwidth, MSSQL databases and more. All those give people the convenience to build up a powerful site in Windows server. ASPHostPortal.com offers ASP.NET hosting starts from $1/month only. They also guarantees 30 days money back and guarantee 99.9% uptime. If you need a reliable affordable ASP.NET Hosting, ASPHostPortal.com should be your best choice.



ASP.NET Hosting - ASPHostPortal.com :: ASP.NET Seo Tips

clock June 21, 2016 20:41 by author Armend

When running an online business, majority of our focus is on the design, architecture of the website and how efficiently it displays our product. These are not the only things that are required to target the infinite Internet audience. One need to keep in mind that the main source of audience come from search engines such as Google, Yahoo, Bing and others. So the application or the website should be able to follow simple rules and handle your business efficiently. ASP.NET application is spreading rapidly and if you are using an ASP.NET website few simple guidelines has to be considered. The below mentioned points need to be implemented:

 

Page Titles

Page titles between tags is one important thing that many fail to practice in SEO. When a search is made in Google, these titles show up as links in the result. So that explains its importance. The common mistake among website owners is giving the same title for all pages. Page titles drive traffic to your site, hence it is important to have a proper title to attract visitors. Adding titles is not as hard as you imagine. If you have a product catalog use your product name as title. You can also choose to give a different title that is related to your product.

Meaningful URL

URLs that are long with query parameters do not look neat and it is difficult for the visitor to remember. Instead use formatted URLs for your static pages. URL which has a meaning explains the content in your website. Although experts agree with using an URL that has query parameters, it is better to have a meaningful URL. Components like UrlRewritingNet can be used for this purpose. Mapping support in URL is offered by IIS7 which has plenty of features.

Structure of the Content

Content without a structure is not possible.  You will have titles, headings, sub headings, paragraphs and others. How would you emphasize some quotes or important points in your content? If you follow the below mentioned steps, the structure of your content will be semantically correct.

  • Divide long stories or parts using headings. Short paragraphs make more sense to the readers. Use tags to bring beauty to your content.
  • If you want to emphasize an important point or quote, place them between tags.

Visitors can create structured content if you use FCKEditor and the like. Integrating these to your website is not complex.

Clean the Source Code

Don’t panic, it is advisable to clean up the source code and minimize the number of codes. The following simple steps will assist you in cleaning the source code: You can use

  •     External stylesheets and not inline CSS
  •     -js files instead of inline JavaScript
  •     HTML comments is not encouraged
  •     Avoid massive line breaking
  •     Avoid using viewstate when not required

The relation between the content and the code (JavaScript, HTML, CSS) determines the ranking of your website. Smaller source codes help build a strong relation.

Crawlable Site

Do not use

  • Silver or flash light for menus or to highlight information
  • Menus based on JavaScript
  • Menus based on buttons
  • Intro-pages

Do use

  • Simple tags wherever possible
  • Sitemap
  • “Alt” for images
  • RSS

Test the Site

What happens to the requests that are sent when the site is slow? Sometimes requests are sent by robots and if they are unable to connect to your site continuously, they drop the site from their index. Enable your site to respond fast to requests even during peak hours. Moreover, visitors don’t like to visit slow sites. Use the various tools available and conduct the stress test for your site. Perform this and locate all the weak parts of the site. Fix them so that your site gets indexed.

Test the AJAX site

Spiders can only run a few parts of your AJAX website because they don’t run JavaScripts. Spiders can only analyze the data and hence they remain invisible to robots. The AJAX sites do not get indexed which does not help in search engine optimization. To make the site spider friendly, try and keep away from initial content loading into the JavaScript. You can also follow this only for pages that you like to index.  Make it easy for robots so that they can navigate. Try this simple trick to see how your AJAX site will appear to the robots. Disable JavaScript from the browser and visit your AJAX site. You can view the pages which robots will index.

 



Cheap ASP.NET 4.5 Hosting

We’re a company that works differently to most. Value is what we output and help our customers achieve, not how much money we put in the bank. It’s not because we are altruistic. It’s based on an even simpler principle. "Do good things, and good things will come to you".

Success for us is something that is continually experienced, not something that is reached. For us it is all about the experience – more than the journey. Life is a continual experience. We see the Internet as being an incredible amplifier to the experience of life for all of us. It can help humanity come together to explode in knowledge exploration and discussion. It is continual enlightenment of new ideas, experiences, and passions


Author Link


 

Corporate Address (Location)

ASPHostPortal
170 W 56th Street, Suite 121
New York, NY 10019
United States

Tag cloud

Sign in