1
선택한 부서를 저장하는 쿠키를 설정하려고합니다. 쿠키는 부서별로 선택 드롭 다운이있는 작은 양식으로 설정됩니다. 이것은 AJAX를 사용하여 게시됩니다.ASP.NET - 내 쿠키가 지속되지 않는 이유는 무엇입니까?
<AcceptVerbs(HttpVerbs.Post)> _
Function ChangeDepartment(ByVal FormValues As FormCollection) As ActionResult
If Response.Cookies("department") IsNot Nothing Then
Response.Cookies("department").Value = FormValues("department")
Else
Dim c As New HttpCookie("department")
c.Value = FormValues("department")
c.Expires = Now.AddDays(7)
Response.Cookies.Add(c)
End If
Return Json(New With {.newDepartment = Response.Cookies("department").Value})
End Function
.newDepartment
변수가 올바른 값으로 제대로 반환됩니다
이 내가 쿠키를 저장하는 방법입니다.
<% Ajax.BeginRouteForm("ChangeDepartment", New AjaxOptions With {.LoadingElementId = "loading", .HttpMethod = "post", .OnSuccess = "function(request) {ajaxMessage('Department change', 'Department changed to: ' + request.get_response().get_object().newDepartment);}"})%>
<select name="department">
<option>Default</option>
<option<%If Request.Cookies("department") Isnot Nothing andAlso Request.Cookies("department").Value = "Supervisor" Then Response.Write (" selected=""selected""") %>>Supervisor</option>
<option<%If Request.Cookies("department") Isnot Nothing andAlso Request.Cookies("department").Value = "Purchasing" Then Response.Write (" selected=""selected""") %>>Purchasing</option>
<option<%If Request.Cookies("department") Isnot Nothing andAlso Request.Cookies("department").Value = "Engineering" Then Response.Write (" selected=""selected""") %>>Engineering</option>
</select>
<input type="submit" value="Change department" />
<% Html.EndForm%>
쿠키가 저장되지 않은 선택 - 드롭 다운이 Default
에 다시 가고 계속하기 때문에, : 내가 쿠키를 검색하고 선택 - 드롭 다운을 구축하는 방법을
이입니다. 내가 뭔가 잘못하고 있는거야?
제게 좀 더 많은 정보를주었습니다. 내가 값을 얻고있는 곳에서 쿠키 값을 지우는 것으로 나타났습니다. 그러나 여하튼 만료 값은 항상 세션 종료입니다. Response.Cookies ("department"). expires = Now.AddDays (7)가 통과하지 못했습니까? – Ropstah