C#登录代码不适用于野生动物园 [英] C# Login code not work on safari

查看:73
本文介绍了C#登录代码不适用于野生动物园的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码登录了我的asp.net网站. 与框架4 它在网络Bowers上成功运行,但在Safari(iphone,ipad)上不起作用 只有当我单击登录"按钮时,他才会刷新页面而不登录.

I used the code below to login to my asp.net website. with framework 4 it's work successfully at web bowers, but didn't work on safari (iphone, ipad) only when I click on login button he refresh the page and not login.

Session["AdminID"] = DT.Rows[0]["Id"].ToString();
Response.Cookies.Add(new HttpCookie("SuperAccountId", DT.Rows[0]["Id"].ToString()));
Response.Cookies["SuperAccountId"].Expires = System.DateTime.Now.AddDays(1);

Response.Cookies.Add(new HttpCookie("SuperAccountName", DT.Rows[0]["Username"].ToString()));
Response.Cookies["SuperAccountName"].Expires = System.DateTime.Now.AddDays(1);
FormsAuthentication.SetAuthCookie(Session["AdminID"].ToString(), true);
FormsAuthentication.RedirectFromLoginPage("admin", true);

//create a cookie
HttpCookie myCookie = new HttpCookie("FirstLoginCookies");

//Add key-values in the cookie
myCookie.Values.Add("first", "1");

//set cookie expiry date-time. Made it to last for next 12 hours.
myCookie.Expires = DateTime.Now.AddHours(12);

//Most important, write the cookie to client.
Response.Cookies.Add(myCookie);

if (Request.QueryString["ReturnUrl"] != null)
{
     string redirectURL = Request.QueryString["ReturnUrl"].ToString();
     Response.Redirect("~" + redirectURL);
}
else
{
     Response.Redirect("~/admin");
} 

推荐答案

请确保您的母版页中没有错误. (如果您使用的是母版页) 然后尝试编辑代码的最后部分,如下所示:

Make sure you have no error in your master page. (If you are using a master page) Then try editing the last part of your code like below:

                if (Request.QueryString["ReturnUrl"] != null)
                {
                    string redirectURL = Request.QueryString["ReturnUrl"].ToString();
                    Response.Redirect("~" + redirectURL, false);

                }
                else
                {
                    Response.Redirect("~/admin", false);
                } 

通过将 Response.Redirect 的第二个参数设置为"false" ,原始页面不会被发布回浏览器,您应该被重定向到新页面页面.

By setting the second parameter of Response.Redirect to "false" the original page won't be posted back to the browser and you should be redirected to the new page.

这篇关于C#登录代码不适用于野生动物园的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆