Asp. Net Core cross platform, open source, cloud-ready da ishlay oladigan dasturlarni qura oladigan framework. Asp. Net Core xususiyatlari


Asp .Net Core da Middleware bilan amaliy mashg’lot


Download 30.73 Kb.
bet3/4
Sana12.02.2023
Hajmi30.73 Kb.
#1191331
1   2   3   4
Bog'liq
ASP NET Core essential info

Asp .Net Core da Middleware bilan amaliy mashg’lot.
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseFileServer();
Static file lar bilan ishlaydigan middlewarelar
app.UseRouting(); - rout bilan ishlaydigan middleware.

app.Use(async (context, next)=>


{
await context.Response.WriteAsync("Middleware 1 ");
await next();
});

//app.UseEndpoints(endpoints =>


//{
// endpoints.MapGet("/", async context =>
// {
// await context.Response.WriteAsync("Main page! ");
// });
// endpoints.MapGet("/Users", async context =>
// {
// await context.Response.WriteAsync("Users page! ");
// });
//});


Static file lar bilan ishlash.

Static file lar bilan ishlay oladigan middlewarelar-

  1. App.UseStatikFiles().

  2. App.UseDefaultFiles().

  3. App.UseFileServer() – universali hisoblanadi

Delevoler Exception Page middleware

  • Configur methodida birinchi bo’lib pipeline ga qo’shilayotgan middleware bu DeveloperException degan middleware

  • if (env.IsDevelopment())

  • {

  • app.UseDeveloperExceptionPage();

  • }

MVC haqida.

  • MVC – Model View Controller – dasturni 3 ta mantiqiy qismlarga bo’luvchi arxitekturaviy pattern deyiladi.

  • Hozirgi vaqtda aksariyat tizimlar quyidagi 3 ta tizimdan iborat bo’ladi:

  1. Presentation (UI) – foydalanuvchi interfasi.

  2. Business Login – tizimning asosiy business logikasi saqlanadigan qatlam.

  3. Data Access.

Controllerdan Viewga ma’lumot uzatish

Controllerdan Viewga ma’lumot uzatishning 3 xil yo’li mavjud :



  1. ViewData

  2. ViewBag

  3. Strongly Typed Views

ViewData – aslida viewdata dictionary, string turidagi kalitni qabul qiladi.


Staff model = _staffRepository.Get(3);
ViewData[“staff”] = model;
ViewData[“title”] = “Staff Details”;

Ushbu ViewData key value per turidagi ma’lumot saqlanuvchi dictionary ekan, u dictionaryga controllerdan turib ma’lumotni beramiz va viewda shu kalit orqali ma’lumotni o’qib olamiz.


Viewda o’qib olish :
@ViewData[“title”]
@{
Var staff = ViewData[“staff”] as StaffManegement.Models.Staff;
}
Va foydalanish quyidagicha : @staff.Firstname , …

ViewBag – dynamic turidagi object.


ViewBag.title = “Staff Details”; uni viewda o’qib olish @ViewBag.title – shu orqali o’qib olinadi.
ViewData bilan ViewBag deyarli bir xil ularning farqi sintaksisda, ularni ishlatganimizda intellijenc ishlamaydi.



Download 30.73 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling