相关疑难解决方法(0)

在302重定向期间发送浏览器cookie

在302重定向期间发回cookie是否有任何问题?例如,如果我创建一个return-to-url cookie并在同一个响应中重定向用户,那么任何(现代)浏览器都会忽略cookie吗?

cookies http http-status-code-302

72
推荐指数
7
解决办法
7万
查看次数

在ASP.NET中的Response.Redirect中传递cookie

我在将ASP.NET中的cookie传递给新URL时遇到问题.我像这样在响应中添加cookie:

Response.Cookies.Add(new HttpCookie("Username", Username.Text));
Run Code Online (Sandbox Code Playgroud)

然后我发出重定向:

Response.Redirect(returnURL);

在我重定向到的新页面上,cookie集合为空.我尝试像这样检索一个cookie:

Request.Cookies["Username"].Value;

任何人都可以想到为什么没有通过cookie?

编辑:

进一步的信息我忘了添加 - 在同一个浏览器会话中的第二次尝试,cookie通过重定向正确传递.

编辑#2:我发现如果我在重定向URL中使用"localhost"而不是实际的域名,那么首次登录时会正确传递cookie.因此,只有当重定向URL是实际的域名时才会起作用.奇怪.

asp.net cookies response.redirect

7
推荐指数
3
解决办法
3万
查看次数

以其他用户身份登录时丢失会话/ cookie

我正在构建dnn模块,允许登录用户以其他用户身份登录.
但我这里有一些有线问题.
这是我注销当前用户并以另一个用户身份登录的方式:

UserInfo userInfo = UserController.GetUserById(portalId, userId);
if (userInfo != null)
{                
    DataCache.ClearUserCache(this.PortalSettings.PortalId, Context.User.Identity.Name);

    if (Session["super_userId"] == null)
    {
        Session["super_userId"] = this.UserId;
        Session["super_username"] = this.UserInfo.Username;
    }

    HttpCookie impersonatorCookie = new HttpCookie("cookieName");
    impersonatorCookie.Expires = DateTime.Now.AddHours(1);
    Response.Cookies.Add(impersonatorCookie);

    Response.Cookies["cookieName"]["super_userId"] = this.UserId.ToString();
    Response.Cookies["cookieName"]["super_username"] = this.UserInfo.Username;

    PortalSecurity objPortalSecurity = new PortalSecurity();
    objPortalSecurity.SignOut();

    UserController.UserLogin(portalId, userInfo, this.PortalSettings.PortalName, Request.UserHostAddress, false);

    Response.Redirect(Request.RawUrl, true);
}
Run Code Online (Sandbox Code Playgroud)

PageLoad()我尝试从这个cookie读取值但它没有读取任何东西:

try
{
    string super_userId = Request.Cookies["cookieName"]["super_userId"];
    string super_username = Request.Cookies["cookieName"]["super_username"];

    if (!String.IsNullOrEmpty(super_userId))
    {
        this.Visible = true;
        this.lblSuperUsername.Text = Session["super_username"].ToString(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net dotnetnuke dotnetnuke-module

3
推荐指数
1
解决办法
1085
查看次数