Я хочу изменить asp.net_sessionId "/" "The Path in Application Tab in asp.net mvc
для, например, в текущем пути мой asp.net_sessionId />https://idea.tataai.com/getidea
и «/" Путь должен быть "/getidea"
Мое приложение развернуто в папке GetIdea, я пытаюсь следить за вещами, но оно не сработало.
protected void Session_Start(object sender, EventArgs e)
{
// Force the session ID to be re-issued with your custom attributes
HttpCookie sessionCookie = new HttpCookie("custsess", Session.SessionID); //ASP.NET_SessionId
sessionCookie.Domain = ".yourdomain.com"; // Your domain (include dot for subdomains)
sessionCookie.Path = "/yourapp"; // Custom path
sessionCookie.HttpOnly = true;
sessionCookie.Secure = true;
Response.Cookies.Remove("custsess");
Response.Cookies.Add(sessionCookie);
}
protected void Application_PreSendRequestHeaders(Object sender, EventArgs e)
{
if (!this.Request.IsLocal && this.Request.IsSecureConnection)
{
this.Response.AppendHeader("Strict-Transport-Security", "max-age=31536000");
}
HttpContext.Current.Response.Headers.Remove("X-Powered-By");
HttpContext.Current.Response.Headers.Remove("X-AspNet-Version");
HttpContext.Current.Response.Headers.Remove("X-AspNetMvc-Version");
HttpContext.Current.Response.Headers.Remove("Server");
var sessionCookie = HttpContext.Current?.Response?.Cookies["custsess"];
if (sessionCookie != null)
{
// Only modify attributes; do NOT change the value
sessionCookie.Domain = ".yourdomain.com";
sessionCookie.Path = "/yourapp";
sessionCookie.HttpOnly = true;
sessionCookie.Secure = true;
}
}
protected void Application_EndRequest()
{
var cookie = Response.Cookies["ASP.NET_SessionId"];
if (cookie != null)
{
cookie.HttpOnly = true;
cookie.Secure = true;
//cookie.SameSite = SameSiteMode.Lax;
cookie.Path = "/Admin/";
}
}
In web.config
using System.Configuration;
using System.Web;
using System.Web.Configuration;
using System.Web.SessionState;
using static Org.BouncyCastle.Math.EC.ECCurve;
namespace MagmaHDI.PreInspection.Server.UI.Web.Class
{
public class CustomSessionIDManager : SessionIDManager
{
//public override string SaveSessionID(HttpContext context, string id, out bool redirected, out bool cookieAdded)
//{
// string result = base.SaveSessionID(context, id, out redirected, out cookieAdded);
// if (cookieAdded)
// {
// HttpCookie cookie = context.Response.Cookies["ASP.NET_SessionId"];
// if (cookie != null)
// {
// cookie.Domain = ".yourdomain.com";
// cookie.Path = "/yourapp";
// cookie.HttpOnly = true;
// cookie.Secure = true;
// }
// }
// return result;
//}
}
}
Подробнее здесь: https://stackoverflow.com/questions/796 ... sp-net-mvc