Я хочу изменить asp.net_sessionId "/" Путь приложения в ASP.NET MVC [закрыто]C#

Место общения программистов C#
Ответить
Anonymous
 Я хочу изменить asp.net_sessionId "/" Путь приложения в ASP.NET MVC [закрыто]

Сообщение Anonymous »

Я хочу изменить вкладку ASP.Net_SessionId "/" Вкладка «Путь в приложении» в ASP.NET MVC
для, например, Текущий мой путь asp.net_sessionId - это «/», что я хочу изменить на что -то вроде «/abc»
Мое текущее приложение размещено как
https://idea.tataai.com/getidea
и "/" Путь должен быть "/getIdea. Следуйте вещам, но это не сработало. < /p>
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/";
}
}
< /code>
in web.config < /p>

< /code>
c# code < /p>
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
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»