User-183185495 posted
Ok I am using a session variable to store a case Id that is linked between tables. I am using .net 3.1 I just need this simple value passed between controllers It appears to only work within the current controller.
public void ConfigureServices(IServiceCollection services) {
services.Configure<CookiePolicyOptions>(options =>
{
options.CheckConsentNeeded = context => true; // consent required
options.MinimumSameSitePolicy = SameSiteMode.None;
});
ervices.AddSession(opts =>
{
opts.Cookie.IsEssential = true; // make the session cookie Essential
});
...
}
This is the second controller where i wish to read in the above session.
public class VesselsController : Controller
{
private readonly MISDBContext _context;
public VesselsController(MISDBContext context) {
_context = context;
GetCompanies();
}
// POST: Vessels/Create
// To protect from overposting attacks, enable the specific properties you want to bind to, for
// more details, see http://go.microsoft.com/fwlink/?LinkId=317598.
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Create([Bind("Id,Name,CountryOfOrigon,CompanyId,IMONumber,Flag,Company,Country,CallSign,MMSI,VesselType,Active,isDeleted,isActive,CreatedDate,CreatedBy,MISObjectId,RelationShipId")] Vessels vessels)
{
if (ModelState.IsValid) {
var realtionShipId = Int32.TryParse(HttpContext.Session.GetString("relationShipId"), out int resultRelationshipId);
Int32.TryParse(HttpContext.Session.GetString("CaseId"), out Int32 resultCaseId);
vessels.isActive = true;
vessels.isDeleted = false;
vessels.CreatedBy = HttpContext.Session.GetString("Intitals");
vessels.LastModfiedDate = DateTime.Now;
vessels.CreatedDate = DateTime.Now;
vessels.LastModfiedBy = HttpContext.Session.GetString("Intitals");
vessels.MISObjectId = resultCaseId;
vessels.RelationShipId = resultRelationshipId;
_context.Add(vessels);
await _context.SaveChangesAsync();
return RedirectToAction("Edit", "Relationships", new { Id = vessels.MISObjectId });
}
GetCompanies();
return View(vessels);
}
}
Its this resultCaseId I have lost the variable and yes I have setup the configure middle ware.
app.UseSession();