Tag: cookies

如何使用MachineKey.Protect作为cookie?

我想加密我在cookie中使用的ID。 我正在使用ASP.NET 4.5,所以我想使用MachineKey.Protect来做到这一点。 码 public static string Protect(string text, string purpose) { if (string.IsNullOrEmpty(text)) return string.Empty; byte[] stream = Encoding.Unicode.GetBytes(text); byte[] encodedValue = MachineKey.Protect(stream, purpose); return HttpServerUtility.UrlTokenEncode(encodedValue); } public static string Unprotect(string text, string purpose) { if (string.IsNullOrEmpty(text)) return string.Empty; byte[] stream = HttpServerUtility.UrlTokenDecode(text); byte[] decodedValue = MachineKey.Unprotect(stream, purpose); return HttpServerUtility.UrlTokenEncode(decodedValue); } 当我使用以下测试数据时: Protect() : […]

获取webbrowser cookie登录

我正在创建一个Windows窗体应用程序,我有一个webbrowser control 。 用户使用webbrowser登录后,我想使用与Microsoft.Http.HttpClient或HttpWebRequest相同的帐户登录,它应该类似于PHP cURL 。 问题是网页只允许每个帐户进行单点登录,如果我使用HttpClient签名,它会将webbrowser踢出去。 我想知道的,如果有可能劫持webbrowser会话或获取cookies并在我的HttpClient或类似的api使用它。 我可以使用webbrowser.Cookie获取一些数据,但是如何将其推送到HttpClient ? 这样的事情是否可能,我可以拿走cookie并使用相同的会话? 如果是这样,怎么样?

如何在cookie中存储字符串并检索它

我想将用户名存储在cookie中,并在用户下次打开网站时检索它。 是否可以创建一个在浏览器关闭时不会过期的cookie。 我使用asp.net c#来创建网站。 如何阻止浏览器提供保存用户名和密码

如何设置asp.net标识cookie到期时间

我使用Asp.Net Identity来控制我的应用程序的授权。 现在,我需要这样做:如果用户在30分钟内没有运行,请跳转到登录页面,当他登录时不选择“isPersistent”复选框。 并且,如果他选择“isPersistent”复选框,请将Cookie的到期日期设置为14天。 我尝试通过像这样更改Startup.Auth.cs来做到这一点: public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”), SlidingExpiration = true, CookieName = WebHelpers.ConstStrings.AUTHCOOKIESNAME }); } 和SignIn代码如下: private async Task SignInAsync(User user, bool isPersistent) { AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie); var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie); if (isPersistent) { AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity); […]

WebAPI OAuth注销 – 如何删除令牌Cookie?

我有一个OAAP登录的WebAPI配置如下: app.UseOpenIdConnectAuthentication( new OpenIdConnectAuthenticationOptions { ClientId = clientId, Authority = authority, PostLogoutRedirectUri = “https://www.microsoft.com/”, Notifications = new OpenIdConnectAuthenticationNotifications { AuthenticationFailed = context => { context.HandleResponse(); context.Response.Redirect(“/Error?message=” + context.Exception.Message); return Task.FromResult(0); } } }); 和使用登录强制执行所有控制器 config.Filters.Add(new System.Web.Http.AuthorizeAttribute()); 我现在想要添加一个名为LogoutController的ApiController(猜猜它是做什么的)。 我发现我可以使用从MVC注销 System.Web.Security.FormsAuthentication.SignOut(); 但我没有这样从WebAPI注销。 我还没有找到任何有关如何从WebAPI注销的信息。 但是我发现注销过程中可能存在错误,cookie被保留并且必须手动删除 ,但是,代码再次是MVC,似乎我无法将HttpCookie放入我的HttpResponseMessage对象中: [HttpGet] public HttpResponseMessage Logout() { FormsAuthentication.SignOut(); // clear authentication cookie HttpCookie cookie1 […]

如何在ASP.Net Core 1.1中响应.Cookies.Append()?

我正在尝试将Globalization添加到Intranet应用程序,使用cookie来允许用户使用文化偏好。 中间件已设置并运行但我遇到了基于UI选择附加到cookie的问题。 该方法直接来自Asp.Net Core文档,如下所示: public void ConfigureServices(IServiceCollection services) { services.Configure( options => { var supportedCultures = new List { new CultureInfo(“en-US”), new CultureInfo(“en-GB”), new CultureInfo(“fr-FR”), new CultureInfo(“es-ES”) }; options.DefaultRequestCulture = new RequestCulture(culture: “en-GB”, uiCulture: “en-GB”); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; }); services.AddLocalization(); services.AddMvc(config => { var policy = new AuthorizationPolicyBuilder() .RequireAuthenticatedUser() .Build(); config.Filters.Add(new AuthorizeFilter(policy)); […]

ASP.NET Core身份validationcookie只收到一次

我正在使用ASP.NET Core开发应用程序,我正在使用自定义Cookie身份validation。 我的CookieAuthenticationOptions是: app.UseCookieAuthentication(new CookieAuthenticationOptions() { AuthenticationScheme = CookieAuthenticationDefaults.AuthenticationScheme, LoginPath = new PathString(“/login”), AccessDeniedPath = new PathString(“/unauthorized/”), AutomaticAuthenticate = true, AutomaticChallenge = true }); cookie创建得很好,我可以在运行应用程序的整个过程中在浏览器设置中看到它。 这是我的HomeController类: public HomeController(IHostingEnvironment env, IAntiforgery antiforgery, IOptions appSettings, TerminalDbContext terminalContext, ILoggerFactory loggerFactory, IHttpContextAccessor _httpContextAccessor) { _env = env; _antiforgery = antiforgery; _appSettings = appSettings; _terminalContext = terminalContext; _logger = loggerFactory.CreateLogger(); […]

如何将CookieCollection插入CookieContainer?

在我收到httpwebrequest的回复后,我希望获得的cookie可以保存,以便在另一个httbwebrequest中使用它们。 但是,我需要将CookieCollection插入CookieContainer。 我怎么做? 试图做: request.Cookiecontainer.add(response.Cookies); 但这样可以避免错误:对象引用未设置为对象的实例。

以编程方式获取.ASPXAUTH cookie值

有没有办法以编程方式获取.ASPXAUTH值。 示例我使用自己的凭据(POST)登录到网站,然后读取响应…它不会返回我用于跟踪会话的CookieContainer中的.APSXAUTH。 任何人都有一个线索,我怎么能得到它并随后发送和发送它? [编辑]以下是我要做的更具体的事情: 将HTTP GET发送到页面。 读取_VIEWSTATE等值 将HTTP POST发送到“登录”页面。 它包括登录信息。 服务器向某个默认页面发送302响应(重定向)。 应该包含表单身份validationcookie,但事实并非如此。 所以我认为跟踪会话可能有比这更好的方法: CookieContainer _cookieJar = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(_url); request.CookieContainer = _cookieJar;

在winforms中使用HttpWebRequest传递cookie?

请参阅以下代码: objCookieContainer = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(“http://website.com/login.php?user=xxx&pass=xxx”); request.Method = WebRequestMethods.Http.Get; request.Timeout = 15000; request.Proxy = null; request.CookieContainer = objCookieContainer; HttpWebRequest newRequest = (HttpWebRequest)WebRequest.Create(“http://website.com/page.php?link=url”); newRequest.Method = WebRequestMethods.Http.Get; newRequest.Timeout = 15000; newRequest.Proxy = null; newRequest.CookieContainer = objCookieContainer; HttpWebResponse response = null; response = (HttpWebResponse)request.GetResponse(); string readerRequest = new StreamReader(response.GetResponseStream(), Encoding.UTF8).ReadToEnd(); response = (HttpWebResponse)newRequest.GetResponse(); string readerNewRequest […]