Freelance Project Requests info@CodeDocu.de Software Development in C# WPF Asp.Net Core Vba Excel Word SQL-Server EF Linq, UWP Net
#

 

 

Cookie reading

string  sIDReference = Request.Cookies["r"].ToString();

 

Cookie writing

The operation with Append is carried out as a save or refresh on multiple execution.

So it does not create multiple cookies with the same name.

CookieOptions options = new CookieOptions();

options.Expires = DateTime.Now.AddDays(1);

Response.Cookies.Append("r", sIDReference, options);

 

In Asp.Net MVC Core2

 

Code Example Read and save

//--< check Referenz >--

//< get RefID >

string sRefPart = Request.Query["r"];

string sIDReference = "";

if (Convert_Methods.IsNumeric(sRefPart))

{ sIDReference =sRefPart;}

else

{

    sIDReference = Convert.ToString(IDOwner);

}

//</ get RefID >

 

if (sIDReference!="")

{

    //-< set ref_cookie >

    if (Request.Cookies["r"] != null)

    {

        sIDReference = Request.Cookies["r"].ToString();

    }

    else

    {

        CookieOptions options = new CookieOptions();

        options.Expires = DateTime.Now.AddDays(1);

        Response.Cookies.Append("r", sIDReference, options);

    }

    //-< set ref_cookie >

}

//--</ check Referenz >--

 

 

Example:

In this case, for example, the query string parameter r = 1 should be read when a web page is called up and then be spelled as a reference in the cookies for one day.

For this, the querystring is first read in MVC Core as a query []

//< get RefID >

string sRefPart = Request.Query["r"];

string sIDReference = "";

if (Convert_Methods.IsNumeric(sRefPart))

{ sIDReference =sRefPart;}

else

{

    sIDReference = Convert.ToString(IDOwner);

}

//</ get RefID >

 

 

Subsequently checked if the cookie already exists.

if (Request.Cookies["r"] != null)

{

        sIDReference = Request.Cookies["r"].ToString();

}

 

Then a cookie is stored on the client computer in the browser

//-< new Cookie for 1 day >-

CookieOptions options = new CookieOptions();

options.Expires = DateTime.Now.AddDays(1);

//< save >

Response.Cookies.Append("r", sIDReference, options);

//</ save >

//-</ new Cookie for 1 day >-

Mobile
»
Browser in Asp.Net Core 2 with Wangkanai
»
Asp.Net Core 2 MVC: Email Sender Client Write.
»
Asp core: Cookie read and write
»
Asp MVC Core: Display HTML text as HTML elements
»
Asp: HTML to Text convert
»
Asp.Net code example

.

Contact for Jobs, Project Requests: raimund.popp@microsoft-programmierer.de