我在Web.Config和Glbal.asax.cs文件中包含以下代码行,当我在浏览器中使用开发人员工具时,我可以看到安全标记未设置为以下Cookie。
还在我的IIS中配置了SSLSettings(选中复选框requireSSL)。
我想将Secure属性设置为所有Cookie,不仅要收到,还要发送给已发送的Cookie。有任何建议请。
在Web.config中:
<httpCookies requireSSL="true"/>
在Global.asax.cs中:
protected void Application_EndRequest(object sender, EventArgs e)
{
if (Request.IsSecureConnection == true && HttpContext.Current.Request.Url.Scheme == "https")
{
Request.Cookies["ASP.NET_SessionID"].Secure = true;
if (Request.Cookies.Count > 0)
{
foreach (string s in Request.Cookies.AllKeys)
{
Request.Cookies[s].Secure = true;
}
}
Response.Cookies["ASP.NET_SessionID"].Secure = true;
if (Response.Cookies.Count > 0)
{
foreach (string s in Response.Cookies.AllKeys)
{
Response.Cookies[s].Secure = true;
}
}
}
}
答案 0 :(得分:1)
有两种方法,web.config中的一个httpCookies元素允许您打开requireSSL,它只传输所有cookie,包括仅在SSL中的会话以及表单身份验证,但是如果你在httpcookies上打开SSL,你还必须打开它在内部表单配置上。
import random
import networkx as nx
def _random_subset(seq,m):
""" Return m unique elements from seq.
This differs from random.sample which can return repeated
elements if seq holds repeated elements.
"""
targets=set()
while len(targets)<m:
x=random.choice(seq)
targets.add(x)
return targets
def barabasi_albert_graph_modified(n, m, seed=None):
if m < 1 or m >=n:
raise nx.NetworkXError(\
"Barabási-Albert network must have m>=1 and m<n, m=%d,n=%d"%(m,n))
if seed is not None:
random.seed(seed)
# Add m initial nodes (m0 in barabasi-speak)
G=nx.empty_graph(m)
G.name="barabasi_albert_graph(%s,%s)"%(n,m)
# Target nodes for new edges
targets=list(range(m))
# List of existing nodes, with nodes repeated once for each adjacent edge
repeated_nodes=[]
# Start adding the other n-m nodes. The first node is m.
source=m
d = {}
while source<n:
# Add edges to m nodes from the source.
G.add_edges_from(zip([source]*m,targets))
# Add one node to the list for each new edge just created.
repeated_nodes.extend(targets)
# And the new node "source" has m edges to add to the list.
repeated_nodes.extend([source]*m)
# Now choose m unique nodes from the existing nodes
# Pick uniformly from repeated_nodes (preferential attachement)
targets = _random_subset(repeated_nodes,m)
deg = np.array(list(G.degree().values()))
deg.sort()
d[G.number_of_nodes()] = deg
source += 1
return G,d