Tag: cookies

如果cookie存在,即使它是在另一个应用程序中创建的,如何检查? (使用JS或C#)

我有几个应用程序,其中一个是管理身份validation的中央应用程序,其中LogOn页面作为IFrame导入到其他应用程序。 当userName和password正确时,我创建一个名为userInfo的cookie。 现在,在当前的应用程序中,我想检查userInfo的cookie是否存在。 我想我应该检查它是否存在于浏览器中(在客户端)。 它必须是可能的,所以我该怎么办呢? 提前致谢。

如何在ASP.NET Core中处理多值cookie?

在完整的.NET框架中,我们支持多值cookie。 例如,cookie可以有多个值: HttpCookie aCookie = new HttpCookie(“userInfo”); aCookie.Values[“userName”] = “patrick”; aCookie.Values[“lastVisit”] = DateTime.Now.ToString(); 另请参阅有关MSDN上的HttpCookie.Values和MSDN上的 ASP.NET Cookie概述 的文档 。 使用ASP.NET Core,多值cookie似乎消失了。 没有HttpCookie.Values和HttpRequest.Cookies返回一个IRequestCookieCollection ,就像从string到string的dictionary一样 我现在应该如何在ASP.NET Core中创建和读取多值cookie? 我怎样才能阅读在Full ASP.NET中创建的多值cookie并在ASP.NET Core中读取它们?

如何从On Premise SharePoint 2013和ADFS获取FedAuth Cookie

我使用Windows Server 2012 R2,ADFS和sharepoint 2013设置了测试环境。我可以使用ADFS作为声明身份提供程序成功登录到Sharepoint 2013。 现在我尝试从我的C#应用​​程序登录到Sharepoint。 我可以使用以下命令从adfs请求saml断言令牌。 现在,我想帮助将saml令牌发布到SharePoint并检索FedAuth cookie,以便我可以被动地登录到SharePoint 2013并从C#应用程序上载文档。 当我调用最后一个方法时PostSharePointSTS()没有设置Cookie。 大部分代码都是Leandro Boffi的帮助 [TestMethod] public void GetSamlTestMethod() { var client = new WebClient(); client.Headers.Add(“Content-Type”, “application/soap+xml; charset=utf-8”); string username = “Administrator@2012r2.local”; string password = “Password1”; string adfsServer = “https://logon.2012r2.local/adfs/services/trust/2005/UsernameMixed”; string sharepoint = “https://portal.2012r2.local/_trust/”; var samlRequest = GetSAML() .Replace(“[Username]”, username) .Replace(“[Password]”, password) .Replace(“[To]”, adfsServer) .Replace(“[applyTo]”, sharepoint); […]

在webbrowser c#应用程序中禁用Cookie读/写

我希望网站无法在webbrowser c#control应用程序中读取cookie或编写新的cookie。 我希望在webbrowser c#应用程序运行时禁用所有网站的所有读/写cookie操作,如果没有,那么我有一个网站列表,其读/写cookie操作应该被禁用。 我使用的是.NET 2.0框架,但也可以使用4.5

在会话结束时或在特定时间过期cookie?

是否可以在会话结束时或特定时间使cookie过期?

ASP.NET MVC cookie不能保存?

为什么这个cookie没有保存在我的global.asax的Session_Start方法中? //new anon user: var authCookie = new HttpCookie(“user-id”, string.Format(“{0}-{1}”, regiserAccountResponse.UserName, regiserAccountResponse.Key)) { Expires = DateTime.MaxValue, Domain = “domain.com”, Secure = true, HttpOnly = true }; //create the new users cookie – there’s no need to call RegisterNewUserSession as this is done in the same call HttpContext.Current.Response.SetCookie(authCookie);

如何在Web API授权属性中获取请求cookie?

在.NET中有两个AuthorizeAttribute类。 一个在System.Web.Http命名空间中定义的: namespace System.Web.Http { // Summary: // Specifies the authorization filter that verifies the request’s System.Security.Principal.IPrincipal. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] public class AuthorizeAttribute : AuthorizationFilterAttribute { // Summary: // Initializes a new instance of the System.Web.Http.AuthorizeAttribute class. public AuthorizeAttribute(); // Summary: // Gets or sets the authorized roles. // […]

如何在用户本地时间设置cookie过期时间?

我想要一个cookie在10分钟内准确到期(仅仅是为了争论)。 如果我使用Expires = DateTime.Now.AddMinutes(30)并且用户在我身后3小时,cookie将在收到后立即过期(这是正确的吗?) 如何设置到期,以便它对用户来说是本地的? 当然,我可以使用JavaScript将该信息与请求一起发送,或者使用某种类型的JS库在客户端创建cookie,或者保留用户配置文件并询问用户的时区,但我看起来很懒惰 – 解决方案。

HttpCookie和Cookie之间的区别?

所以我很困惑msdn和其他教程告诉我使用HttpCookies通过Response.Cookies.Add(cookie)添加cookie。 但那就是问题所在。 Response.Cookies.Add只接受Cookies而不接受HttpCookies,我收到此错误: 无法从’System.Net.CookieContainer’转换为’System.Net.Cookie’ 另外,Response.Cookies.Add(cookie)和Request.CookieContainer.Add(cookie)之间有什么区别? 感谢您的帮助,我正在尝试使用C#自学。 // Cookie Cookie MyCookie = new Cookie(); MyCookie.Name = “sid”; MyCookie.Value = SID; MyCookie.HttpOnly = true; MyCookie.Domain = “.domain.com”; // HttpCookie HttpCookie MyCookie = new HttpCookie(“sid”); MyCookie.Value = SID; MyCookie.HttpOnly = true; MyCookie.Domain = “.domain.com”; Response.Cookies.Add(MyCookie);

设置/更新aspxauth和asp.net_sessionid cookie的到期日期

我想知道是否有一种方法可以设置您的.NET应用程序来设置和更新浏览器中的aspxauth和asp.net_sessionid cookie的到期时间? 根据我的看法,cookies的到期日期类似于1/1/0001,告诉浏览器保留它们直到浏览器关闭(我已经使用Chrome观察到了这一点)。 我想设置一个明确的时间,但是,我需要在每个请求上更新该时间。 我试图用以下代码执行此操作: var timeoutMins = Session.Timeout; if (Response.Cookies.Count > 0) { foreach (string s in Response.Cookies.AllKeys) { if (s == FormsAuthentication.FormsCookieName || s.ToLower() == “asp.net_sessionid”) { Response.Cookies[s].Expires = DateTime.Now.AddMinutes(timeoutMins); } } } 我尝试在global.asax End_Request事件中执行此操作,虽然这似乎不是一个好地方,因为它每页触发几次并且您无法访问sessionstate超时; 此外它只在登录和注销时触发,所以基本上我可以设置一次,但我永远不能更新它。 这会导致我的用户在登录后15分钟登出,即使他们已经处于活动状态。 好像会有某些设置告诉.net来处理这个问题? 我知道这是一个奇怪的请求,但这是该项目的安全要求,所以我试图让它工作!