나는 Asp.Net에서 응용 프로그램을 가지고 있으며 버튼을 클릭하면 다른 매핑 응용 프로그램을 시작해야합니다. 해당 응용 프로그램에서 사용자 이름 및 전자 메일 같은 사용자의 자격 증명이 필요합니다. 그래서, 쿠키를 설정하고 그 응용 프로그램에 쿠키 도메인을 수정하려고했지만 해당 응용 프로그램에서 쿠키를 볼 수 없습니다. 나는 무엇이 잘못되고 있는지 또는 쿠키를 실수로 잘못 작성했는지 정말로 확신하지 못합니다.Asp.Net의 다른 응용 프로그램에서 쿠키 읽기
MembershipUser usr = Membership.GetUser();
Guid newUserId = (Guid)usr.ProviderUserKey;
HttpCookie SampleCookie = new HttpCookie("UserInfo");
Response.Cookies["UserInfo"]["UserName"] = usr.UserName;
Response.Cookies["UserInfo"]["Email"] = usr.Email;
SampleCookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(SampleCookie);
SampleCookie.Domain = "http://157.182.212.204/MAP";
다시 한번 감사드립니다. MAP 응용 프로그램에 대한
코드 :
function Get_Cookie(check_name) {
// first we'll split this cookie up into name/value pairs
// note: document.cookie only returns name=value, not the other components
var a_all_cookies = document.cookie.split(';');
var a_temp_cookie = '';
var cookie_name = '';
var cookie_value = '';
var b_cookie_found = false; // set boolean t/f default f
for (i = 0; i < a_all_cookies.length; i++)
{
// now we'll split apart each name=value pair
a_temp_cookie = a_all_cookies[i].split('=');
// and trim left/right whitespace while we're at it
cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
// if the extracted name matches passed check_name
if (cookie_name == check_name)
{
b_cookie_found = true;
// we need to handle case where cookie has no value but exists (no = sign, that is):
if (a_temp_cookie.length > 1)
{
cookie_value = unescape(a_temp_cookie[1].replace(/^\s+|\s+$/g, ''));
}
// note that in cases where cookie is initialized but no value, null is returned
return cookie_value;
break;
}
a_temp_cookie = null;
cookie_name = '';
}
if (!b_cookie_found)
{
return null;
}
}
function Delete_Cookie(name, path, domain) {
if (Get_Cookie(name)) document.cookie = name + "=" +
((path) ? ";path=" + path : "") +
((domain) ? ";domain=" + domain : "") +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
alert(Get_Cookie("UserName"));
아래에 주어진 WVWRAPICt 페이지 RESET.aspx.cs의 코드 ... 이것은 쿠키
using System;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
public partial class RESET_RESET : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Menu Nav = Master.FindControl("NavigationMenu1") as Menu;
MenuItemCollection Menu = Nav.Items;
foreach (MenuItem item in Menu)
{
string name = item.Text.ToString();
if (name == "ADMIN")
{
item.Enabled = User.IsInRole("Administrator");
}
if (name == "ICT")
{
item.Selected = true;
}
else
{
item.Selected = false;
}
}
}
protected void Button2_Click(object sender, EventArgs e)
{
MembershipUser usr = Membership.GetUser();
Guid newUserId = (Guid)usr.ProviderUserKey;
HttpCookie SampleCookie = new HttpCookie("UserInfo");
SampleCookie["UserName"] = usr.UserName;
SampleCookie["Email"] = usr.Email;
string connectionString =
ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
string checkSiteEventIDSQL = "Select * from UserProfiles WHERE UserId='" + newUserId + "'";
using (SqlConnection myConnection1 = new SqlConnection(connectionString))
{
try
{
myConnection1.Open();
SqlCommand myCommand1 = new SqlCommand(checkSiteEventIDSQL, myConnection1);
SqlDataReader myReader = myCommand1.ExecuteReader();
if (myReader.HasRows)
{
while (myReader.Read())
{
string Agency = (myReader.GetValue(2)).ToString();
SampleCookie["Agency"] = Agency;
}
}
}
catch (Exception ex)
{
}
finally
{
myConnection1.Close();
}
}
SampleCookie.Expires = DateTime.Now.AddDays(1);
SampleCookie.Domain = "157.182.212.204/MAP";
// SampleCookie.Path = "/MAP";
Response.Cookies.Add(SampleCookie);
Response.Redirect("http://157.182.212.204/MAP/index.html");
}
}
시도했지만 작동하지 않는 것 같습니다 ... 다른 아이디어 plzzzzz – user613037
자세한 정보로 업데이트되었습니다. –
그건 도움이되지 않았어. 사실 내 응용 프로그램은 157.182.212.204/WVWRAPICT이고 버튼을 클릭하면 157.182.212.204/MAP라고 부르기 때문에 동일한 FQDN이라고 생각합니다. 나는 그 밖의 무엇이 문제가 될지 확신하지 못합니다. 제발 도와주세요. 그리고 이것은 제가 이런 종류의 일을하고있는 주먹입니다. 도움을 주셔서 감사합니다 .... – user613037