ASP.NET State Service Tutorial : Implementing State Server Session In ASP.NET

In this article, we will show you how can we implement “state server” session state management technique in asp.net

Bellow are steps for implementing “State Server” session management technique.

  • Add configuration in of Web.Config.

<sessionState mode=”StateServer” stateConnectionString=”tcpip=127.0.0.1:42424″/>

Here, mode=”StateServer” means session mode is “State Server”. Other modes are inproc, SQL server & custom.
stateConnectionString=”tcpip=127.0.0.1:42424″ means session state windows service is running on 127.0.0.1 (this is same machine where I am running my application as well as service. If you are running windows service on other machine then put that machines IP) on port 42424 (this is default port on which service runs. This can bechanged in registry).

  • Starting “StateServer” windows service

Go to services (gor to Run => services.msc) & find “ASP.NET State Service”.

Change startup type of“ASP.NET State Service”to “Automatic” & start the service.

This configuration is enough if you have state server on same machine.

You might get bellow error if you are using other machine for storing state.

“Unable to make the session state request to the session state server. Please ensure that the ASP.NET State service is started and that the client and server ports are the same. If the server is on a remote machine, please ensure that it accepts remote requests by checking the value of HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection. If the server is on the local machine, and if the before mentioned registry value does not exist or is set to 0, then the state server connection string must use either ‘localhost’ or ’127.0.0.1′ as the server name.”

To solve this error follow bellow steps

  • Go to machine where windows service is running.
  • Go to registry (Go to Run => regedit)
  • Go to this path -> “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\aspnet_state\Parameters\AllowRemoteConnection”
    regedit

  • Change Value of parameter “AllowRemoteConnection” from 0 to 1.

Here you also change port number as well by changing Value of “PORT” parameter.

  • Now restart windows service.

Hope fully after doing this error will be gone & you will be able to implement “StateServer” session management technique successfully in ASP.NET.

HostForLIFE.eu revolutionized hosting with Plesk Control Panel, a Web-based interface that provides customers with 24×7 access to their server and site configuration tools. Plesk completes requests in seconds. It is included free with each hosting account. Renowned for its comprehensive functionality – beyond other hosting control panels – and ease of use, Plesk Control Panel is available only to HostForLIFE’s customers. They offer a highly redundant, carrier-class architecture, designed around the needs of shared hosting customers.

ASP.NET MVC 6 Tutorial :: How to Search Record in MVC With Ajax and jQuery?

Today’s turotial is about how to search record in MVC with Ajax and jQuery. This code will filter out all matching records group by table column name.
hflnet52

First thing that you should do is create an empty ASP.NET MVC project. Now, add two class to your model. Employee and DemoContext and write the following code:

namespace SearchingDemo.Models
{
public class Employee
{
[Key]
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Position { get; set; }
}
}
namespace SearchingDemo.Models
{
public class DemoContext : DbContext
{
public DbSet<Employee> Employees { get; set; }
}
}

Add a Home Controller. Now, Add index Action to controller. and create corresponding view.

public ActionResult Index()
{
return View();
}

Now, write the following code to Index View.
<link href="~/Content/Style.css" rel="stylesheet" />
<script src="~/Content/jquery-2.1.1.min.js"></script>
<script src="~/Content/CustomJs.js"></script>
<h2>Seaching Demo</h2>
<div class="divFind">
<table>
<tr>
<td>
<input type="text" id="txtSearch" />
</td>
<td>
<input type="button" id="btnSearch" value="Seach" />
</td>
</tr>
</table>
</div>
<div id="divList">
</div>

Write the .JS code for click event on seach button to get filtered result. add following .JS code.

$(document).ready(function () {
$('#btnSearch').on('click', function () {
var getkey = $('#txtSearch').val();
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: 'Home/Search',
data: "{ 'searchKey':' " + getkey + "' }",
success: function (data) {
BindData(data);
},
error: function (data) {
alert('Error in getting result');
}
});
});
});
function BindData(data) {
var ulList = '<ul>';
var resultType = ["FirstName", "LastName", "Position"];
$.each(data, function (i, d) {
ulList += '<li class="SeachType">' + resultType[i] + '</li>';
if (d.length > 0) {
$.each(d, function (key, value) {
ulList += '<li>' + value.FirstName + ' - ' + value.LastName + ' - ' + value.Position + '</li>'
});
} else {
ulList += '<li><span class="red">No Results</span></li>';
}
});
ulList += '</ul>'
$('#divList').html(ulList);
}

Javascript code calling search function, which is written in controller. Add search function to your controller.

public JsonResult Search(string searchKey)
{
DemoContext dbObj = new DemoContext();
var getKey = searchKey.Trim();
var getFirstName = dbObj.Employees.Where(n => n.FirstName.Contains(getKey)).ToList();
var getLastName = dbObj.Employees.Where(n => n.LastName.Contains(getKey)).ToList();
var getPostion = dbObj.Employees.Where(n => n.Position.Contains(getKey)).ToList();
IList<IList<Employee>> getTotal = new List<IList<Employee>>();
getTotal.Add(getFirstName);
getTotal.Add(getLastName);
getTotal.Add(getPostion);
int count = getTotal.Count();
return Json(getTotal);
}

 

HostForLIFE.eu ASP.NET MVC 6 Hosting
HostForLIFE.eu 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 customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.