Adel
Adel
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
Thank you guys for trying to help
24 replies
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
I'll test that out when I'm back home working atm
24 replies
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
Wasn't sure if I should catch the error in the controller or program.cs
24 replies
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
I'm not sure what to add to catch these errors I made this website a year ago so my knowledge is very limited
24 replies
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
I log in works great but like I said its random when it logs me out but its quick wont last more then 5mins
24 replies
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
Wasnt sure if it would be my program.cs or my controller
24 replies
CC#
Created by Adel on 11/16/2023 in #help
Logging out randomly
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SurveyTest3.Models;
using System;

var builder = WebApplication.CreateBuilder(args);

// Add configuration
builder.Configuration.AddJsonFile("appsettings.json");

// Add services to the container.
builder.Services.AddControllersWithViews();

// Retrieve connection string
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
}
builder.Services.AddSingleton<ISurveyDBLayer>(new SurveyDBLayer(connectionString));
builder.Services.AddScoped<IAdminDBLayer>(provider =>
{
return new AdminDBLayer(connectionString);
});

// Add session configuration
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.SlidingExpiration = false; // Disable sliding expiration
options.ExpireTimeSpan = TimeSpan.FromMinutes(30); // Set the absolute expiration time
options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax; // Adjust based on your needs
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseSession(); // Add session middleware

app.UseAuthentication(); // Add authentication middleware
app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using SurveyTest3.Models;
using System;

var builder = WebApplication.CreateBuilder(args);

// Add configuration
builder.Configuration.AddJsonFile("appsettings.json");

// Add services to the container.
builder.Services.AddControllersWithViews();

// Retrieve connection string
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
if (string.IsNullOrEmpty(connectionString))
{
throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
}
builder.Services.AddSingleton<ISurveyDBLayer>(new SurveyDBLayer(connectionString));
builder.Services.AddScoped<IAdminDBLayer>(provider =>
{
return new AdminDBLayer(connectionString);
});

// Add session configuration
builder.Services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromMinutes(30);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});

builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddCookie(options =>
{
options.SlidingExpiration = false; // Disable sliding expiration
options.ExpireTimeSpan = TimeSpan.FromMinutes(30); // Set the absolute expiration time
options.Cookie.SameSite = Microsoft.AspNetCore.Http.SameSiteMode.Lax; // Adjust based on your needs
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseSession(); // Add session middleware

app.UseAuthentication(); // Add authentication middleware
app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
24 replies
CC#
Created by Adel on 6/28/2023 in #help
❔ Site speed,
I will try @xeronik | aws > azure
14 replies
CC#
Created by Adel on 6/28/2023 in #help
❔ Site speed,
The server is godaddy but when I remove all the car images its fast
14 replies
CC#
Created by Adel on 6/28/2023 in #help
❔ Site speed,
I am storing images as varbinary(max) let me know if I should do something else
14 replies
CC#
Created by Adel on 6/28/2023 in #help
❔ Site speed,
this is my first website ^
14 replies
CC#
Created by Adel on 6/21/2023 in #help
❔ Update sql code not working
I'll try to debug in my SQL statement again but it didn't do anything last time I debugged my controller and I screenshotted what happened
6 replies
CC#
Created by Adel on 6/21/2023 in #help
❔ Update sql code not working
and here is my controller, my insert works fine my delete works great but updating doesn't work i am not sure if the issue is because of image but maybe someone can see something I can't
// POST: Home/UpdateCar
[HttpPost]
public IActionResult UpdateCar(Car car)
{
if (!ModelState.IsValid)
{
return View("Edit", car);
}

try
{
Car updatedCar = _surveydb.UpdateCar(car); // Replace with your method to update the car in the repository
return RedirectToAction("Inventory"); // Redirect to the "Inventory" action method
}
catch (Exception ex)
{
// Handle the exception
ModelState.AddModelError("", "An error occurred while updating the car. Please try again.");
return View("Edit", car);
}
}
// POST: Home/UpdateCar
[HttpPost]
public IActionResult UpdateCar(Car car)
{
if (!ModelState.IsValid)
{
return View("Edit", car);
}

try
{
Car updatedCar = _surveydb.UpdateCar(car); // Replace with your method to update the car in the repository
return RedirectToAction("Inventory"); // Redirect to the "Inventory" action method
}
catch (Exception ex)
{
// Handle the exception
ModelState.AddModelError("", "An error occurred while updating the car. Please try again.");
return View("Edit", car);
}
}
when clicking on update it updates the page with the new numbers but now the database. Thank you 😄
6 replies
CC#
Created by Adel on 4/20/2023 in #help
❔ Select statement to view in html
This is my models public class Carinformation { public int ID { get; set; } public string Title { get; set; } public decimal? Price { get; set; } public int? Miles { get; set; } public string? VinNumber { get; set; } public decimal? MilesPerGallon { get; set; } public string? Engine { get; set; } public string? Color { get; set; } public string? DriveType { get; set; } public string? Transmission { get; set; } public byte[]? Image { get; set; } public int? Year { get; set; } } public class CarImage { public int ID { get; set; } public int CarInformationID { get; set; } public byte[]? Image { get; set; } } My tables are getting inserted correctly Ex: Car Id is 1 will have all the details Car Id 1 in carimage would have 3 rows for the 3 uploaded images Now when joining how could I show them all in 1 row? or do i need to make separate queries because I can't figure out a way to show them in my html Note: My select statement is obviously wrong just wanted to keep it simple and also I dont have image from carimage in this code as well.
3 replies
CC#
Created by Adel on 4/16/2023 in #help
❔ image finally stored as byte but when viewing I'm not getting an image
So you want me to save the image to my desktop on a file
13 replies
CC#
Created by Adel on 4/16/2023 in #help
❔ image finally stored as byte but when viewing I'm not getting an image
Never mind sorry to confuse you I'm a beginner so it's hard to understand the terminology
13 replies
CC#
Created by Adel on 4/16/2023 in #help
❔ image finally stored as byte but when viewing I'm not getting an image
Instead of cardetails
13 replies
CC#
Created by Adel on 4/16/2023 in #help
❔ image finally stored as byte but when viewing I'm not getting an image
Can the image file be a different function then the one I have
13 replies
CC#
Created by Adel on 4/16/2023 in #help
❔ image finally stored as byte but when viewing I'm not getting an image
What would be the correct approach if you got time
13 replies
CC#
Created by Adel on 4/16/2023 in #help
❔ image finally stored as byte but when viewing I'm not getting an image
Thank you ❤️
13 replies