avatar
Mahyar

کاربر

  • 1401/04/14
  • 0
  • 71
1401/04/14 |
backend

خز


با سلام خدمت استاد بابایی و بقیه اساتید 


من الان دارم با  vs 2022 و net 6  کار میکنم 
که فایل Startup.cs نداره

و من با سرچی که انجام دادم کد هایی مربوط  Startup.cs در Program.cs وارد کردم الان پذوزه بدن هیچ مشکلی بیلد میشه ....

فقط دستور 

Add-Migration -Context IdentityDatabaseContext inti

که اجرا میکنم خطا میده 

Unable to create an object of type 'IdentityDatabaseContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728

 

فایل Program.cs به این صورت تغییر دادم 

 

using Microsoft.EntityFrameworkCore;
using Persistence.Contexts;

var builder = WebApplication.CreateBuilder(args);

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

var app = builder.Build();

ConfigurationManager configuration = builder.Configuration; // allows both to access and to set up the config
IWebHostEnvironment environment = builder.Environment;


#region  Connection String
string connection = @"Data Source=d-it3\sqlserver2019,41828;Initial Catalog=DbShop;Integrated Security=True;";
builder.Services.AddDbContext<DataBaseContext>(option => option.UseSqlServer(connection));


//builder.Services.AddIdentityService(Configuration);
builder.Services.AddAuthorization();
builder.Services.ConfigureApplicationCookie(option =>
{
    option.ExpireTimeSpan = TimeSpan.FromMinutes(10);
    option.LoginPath = "/account/login";
    option.AccessDeniedPath = "/Account/AccessDenied";
    option.SlidingExpiration = true;
});
#endregion


// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

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

app.UseRouting();


app.UseAuthentication();
app.UseAuthorization();




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

app.Run();

 

ممنون

 


خب شما که ایدنیتی رو تو سرویس اضافه نکردید که.


  • 1401/04/25

میشه لطفا توضیح بدید چجوری باید ایدنتیتی رو اضافه کنم 

 

من این خط رو تو Program.cs اضافه کردم ولی همین جور که میبینید کامنتش کردم ... چون خطا میگرفتم و دستور AddIdentityService تو Services نمیشناخت

 

builder.Services.AddIdentityService(Configuration)

 

لطفا اگر ممکنه توضیح بدید چطور ایدنتی تی  اضافه کنم 

 

 



پاسخی برای این باگ ارسال کنید

لطفا کدها را درون قطعه کد ارسال نمایید

برای ارسال پاسخ باید وارد حساب کاربری خود شوید
ورود به حساب کاربری