MVC C# Cookie management

Declare Object Class

public class LogedInInfo
    {
        public int UserId { get; set; }
        public string UserName { get; set; }
        public string ShopID { get; set; }
        public string ShopName { get; set; }
        public string CounterID { get; set; }
    }


Assign object value and set Cookie

LogedInInfo info = new LogedInInfo(); // assign object to info
var json = JsonConvert.SerializeObject(info);
HttpCookie cookie = new HttpCookie("LogedInInfo", json);
cookie.Expires = DateTime.Now.AddDays(30);                 
HttpContext.Response.Cookies.Add(cookie);
           

Get cookie value from object

 private LogedInInfo GetLogedInInfo()
{
 LogedInInfo info= new LogedInInfo();
 if (HttpContext.Request.Cookies["LogedInInfo"] != null)
  {
  HttpCookie cookie = HttpContext.Request.Cookies.Get("LogedInInfo");
  info = Newtonsoft.Json.JsonConvert.DeserializeObject(cookie.Value) as LogedInInfo;
   }
    return info;
  }

Clear Cookie/Remove Cookie

 if (Request.Cookies["LogedInInfo"] != null)
 {
  var c = new HttpCookie("LogedInInfo");
  c.Expires = DateTime.Now.AddDays(-1);
  Response.Cookies.Add(c);
  }

Get Cookie in ASP.NET *.aspx.cs

LogedInInfo info = new LogedInInfo();
if (Request.Cookies["LogedInInfo"] != null)
{
var value = Request.Cookies["LogedInInfo"].Value;
info = Newtonsoft.Json.JsonConvert.DeserializeObject(value) as LogedInInfo;
}
return info;

Other userfull tricks

//Response.Cookies.Add(cookie);
//HttpContext.Response.Cookies.Remove(“some_cookie_name”);
//HttpContext.Response.SetCookie(cookie);

Response.SetCookie(cookie); //SetCookie is used for update the cookies.
Response.Cookie.Add(cookie); //This is used for Add cookies.

http://stackoverflow.com/questions/19128507/using-cookie-in-asp-net-mvc-4

http://stackoverflow.com/questions/6797350/asp-net-mvc-cookie-implementation

Advertisements

SQL SERVER – Attach mdf file without ldf file in Database

USE [master]
GO
— Method 1: I use this method
EXEC sp_attach_single_file_db @dbname=’TestDb’,
@physname=N’C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf’
GO

— Method 2:

CREATE DATABASE TestDb ON
(FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf’)
FOR ATTACH_REBUILD_LOG
GO

— Method 3:
CREATE DATABASE TestDb ON
( FILENAME = N’C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\TestDb.mdf’)
FOR ATTACH
GO

3579_CreateDatabase4Attach

Attaching the Damaged SQL Server Database

USE [master]
GO

CREATE DATABASE [TestDB_Repair]
CONTAINMENT = NONE
ON  PRIMARY
( NAME = N’TestDB_Repair_file1′,
FILENAME = N’E:\MSSQL\TestDB_Repair_1.mdf’,
SIZE = 8MB ,
MAXSIZE = UNLIMITED,
FILEGROWTH = 64MB)
LOG ON
( NAME = N’TestDB_Repair_log_file1′,
FILENAME = N’E:\MSSQL\TestDB_Repair_1.ldf’,
SIZE = 8MB,
MAXSIZE = 2048GB,
FILEGROWTH = 32MB)

Now we set the database offline.

USE master
GO

ALTER DATABASE [TestDB_Repair] SET OFFLINE WITH ROLLBACK IMMEDIATE
GO

At this point we can change the file location of our new database to point to our orphaned mdf file and set the location of the log file to a non-existent file.

USE master
GO

ALTER DATABASE [TestDB_Repair] MODIFY FILE(NAME=’TestDB_Repair_file1′, FILENAME= ‘E:\MSSQL\TestDBCopy.mdf’)
ALTER DATABASE [TestDB_Repair] MODIFY FILE(NAME=’TestDB_Repair_log_file1′, FILENAME= ‘E:\MSSQL\TestDBCopy.ldf’)
GO
Let’s bring the database back online.

USE master
GO

ALTER DATABASE [TestDB_Repair] SET ONLINE
GO

2

Rebuilding the SQL Server Transaction Log

USE master
GO

DBCC TRACEON(3604)
GO

ALTER DATABASE TestDB_Repair SET EMERGENCY
GO

ALTER DATABASE TestDB_Repair SET SINGLE_USER
GO

DBCC CHECKDB('TestDB_Repair', REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS
GO

ALTER DATABASE TestDB_Repair SET MULTI_USER
GO

3

http://littleprograming.blogspot.com/2015/10/sql-server-attach-mdf-file-without-ldf.html

A program of bubble sort in ascending order

/* A program of bubble sort in ascending order */

#include

int main(void)
{
int i,j,n,array[50],tem;

printf(“Enter how many number are you want to sort , maximum size is 50 :\n”);
scanf(“%d”,&n);

printf(“Now Enter %d numbers :\n”,n);
for(i=0;i
scanf(“%d”,&array[i]);

for(i=1;i<=n-1;i++)
{
for(j=0;j<n-i;j++)

{

if(array[j]>array[j+1e])
{
tem=array[j];
array[j]=array[j+1];
array[j+1]=tem;

}
}
}
printf(“The sorted number are :\n”);
for(i=0;i<n;i++)
printf(“%3d”,array[i]);

return 0;
}

Programming video tutorials

Here are some video  tutorials of programming . if you fell any interest , please visit the following link

Solution of Problem-A- Back to high school physics

#include<stdio.h>
int main()
{
long long int v,t;
while(scanf(“%lld%lld”,&v,&t)!=EOF)
printf(“%lld”,2*v*t);
}

Solution of Problem-D- Boxa of Bricks

#include<stdio.h>
int main()
{
int m=0,i,n,a[100];
do
{ (more…)

Solution of Problem-C- Jolly Jumpers

#include<stdio.h>
int main()
{
int n,a[3000]; (more…)

Solution of problem-B- Pizza Cutting

#include<stdio.h>
int main()
{
long long int n,a=0;
while(scanf(“%lld”,&n)!=EOF)
{
if(n<0)
break;
else
{
a=(n*(n+1))/2;
printf(“%lld”,a+1);
}
}
}

Skills most requested by employers of graduates

System Administration is likely to require: Linux, Windows, Apache, IIS, BIND, MySQL, MSSQL, Oracle, Cisco.

For Application Development, you’ll need: C++, C#, Java with Visual Basic

Web Development will most likely requires: Apache, PHP, MySQL, ASP.NET, IIS, MSSQL, HTML, XML

What are the most in-demand programming skills for 2011 and beyond, & why?

Being good at code is always in demand, and it is far more important to be effective at reading code. To practice, you can take a library that does something you understand (say convert a csv into a data-structure) then strip out the comments and trace it. Extra points goes to the one that can do this under some kind of source obfuscation. I’ve met too many programmers who can’t read code at a serious level, and I’ve met programmers that rely on superfluous comment; however, there is nothing except hope and trust that ensure the comment and the code are in parity.
(more…)

What programming language should I learn?

You will become a good programmer only by – programming a lot. Many students don’t program outside their labs and college projects, and they never become good programmers. Try to do some coding in your free time. Try to solve Project Euler problems in your favorite programming language, or try to build a website of your own. (more…)

Solution of problem no 2 of java

Season