سؤال

مستوحاة من هذا CodingHorror المادة،"حماية الكوكيز الخاص بك:HttpOnly"

كيف يمكنك تعيين هذه الخاصية ؟ في مكان ما في الشبكة التكوين?

هل كانت مفيدة؟

المحلول

إذا كنت تستخدم ASP.NET 2.0 أو أكبر ، يمكنك تشغيله في شبكة الإنترنت.ملف التكوين.في <system.web> القسم أضف السطر التالي:

<httpCookies httpOnlyCookies="true"/>

نصائح أخرى

مع الدعائم ريك (التعليق الثاني في بلوق وظيفة المذكورة) هنا المقالة MSDN على httpOnlyCookies.

خلاصة القول هي أنه يمكنك فقط إضافة المقطع التالي في النظام الخاص بك.ويب قسم الويب الخاص بك.التكوين:

<httpCookies domain="" httpOnlyCookies="true|false" requireSSL="true|false" />

إذا كنت تريد أن تفعل ذلك في الاستخدام النظام.ويب.HttpCookie.HttpOnly مكان الإقامة.

هذا هو مباشرة من MSDN مستندات:

// Create a new HttpCookie.
HttpCookie myHttpCookie = new HttpCookie("LastVisit", DateTime.Now.ToString());
// By default, the HttpOnly property is set to false 
// unless specified otherwise in configuration.
myHttpCookie.Name = "MyHttpCookie";
Response.AppendCookie(myHttpCookie);
// Show the name of the cookie.
Response.Write(myHttpCookie.Name);
// Create an HttpOnly cookie.
HttpCookie myHttpOnlyCookie = new HttpCookie("LastVisit", DateTime.Now.ToString());
// Setting the HttpOnly value to true, makes
// this cookie accessible only to ASP.NET.
myHttpOnlyCookie.HttpOnly = true;
myHttpOnlyCookie.Name = "MyHttpOnlyCookie";
Response.AppendCookie(myHttpOnlyCookie);
// Show the name of the HttpOnly cookie.
Response.Write(myHttpOnlyCookie.Name);

يفعل ذلك في التعليمات البرمجية يسمح لك اختيار انتقائي ملفات تعريف الارتباط التي يتم HttpOnly والتي ليست كذلك.

ومن المثير للاهتمام وضع <httpCookies httpOnlyCookies="false"/> لا يبدو أن تعطيل httpOnlyCookies في ASP.NET 2.0.تحقق من هذه المادة عن SessionID و الدخول في مشاكل مع ASP .NET 2.0.

يبدو أن مايكروسوفت اتخذت قرار لا تسمح لك تعطيله من شبكة الإنترنت.config.تحقق من هذا وظيفة على forums.asp.net

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top