Asp-klassik veb-sahifa tomonidan atalgan. NET MAQOMOTI obyekti vaqtida ConfigurationManager.App/ConnectionSettingsni qanday o'zgartirish mumkin?

NET MAQOMOTI obyektini ishga tushiraman va ConfigurationManager.AppSettings va ConfigurationManager.ConnectionStrings xususiyatlarini yangilashni xohlayman. O'rnatish moslama faylida sozlamalarim bo'lsa ham, masalan, "ComLib.dll.config" ushbu sozlamalar ish vaqtida mavjud emas.

Quyidagi usullardan foydalanib, ASP klassi veb-sahifasidan MAQOMOTI obyektini yaratish uchun qo'ng'iroq qilaman:

Dim COMObject
Set COMObject = Server.CreateObject("COMAPI.COMObject")

Mening VS2010 tuzatuvchisini mening .NET MAQOMOTI ob'ektini (COMAPI.COMObject) Oluşturucusuna kiritish uchun foydalaning. Bu shuni anglatadiki, yuklangan narsani tekshirish uchun ConfigurationManager ni sinab ko'rdim.

"Assembly.GetExecutingAssembly" va "Assembly.GetCallingAssembly" ham "ComLib.dll" assemble uchun to'liq yo'l bo'lgan natijaga ega. ro'yxatdan o'tgan joy. Men nima kutmoqdaman. Bu manzil shuningdek, ConfigurationManager ichiga tortilmaydigan "ComLib.dll.config" faylga ham ega.

Quyidagi buyruqni ishlatib AppSettings ni tozalashga harakat qilsam, bir istisno ro'y beradi:

ConfigurationManager.AppSettings.Clear();

The exception is: "Server object: 006~ASP 0177~Server.CreateObject Failed~80131902"

Mening fikrimcha, yuqoridagi istisnosiz "AppSettings faqat o'qiladi" ning ASP Classic talqini, lekin men 100 foiz ishonchim yo'q.

"ComLib.dll.config" faylini yuklayotgan va AppSettings elementlarining har birini ishlaydigan ConfigurationManager.AppSettings sozlamalari o'rnatilmagan bo'lsa ham, bu istisnoga sabab bo'ladi: "Server obyekti: 006 ~ ASP 0177 ~ Server.CreateObject muvaffaqiyatsiz ~ 80131902" .

.NET MAQOMOT ob'ektida foydalanadigan kod quyidagicha:

Assembly comApiAssembly = Assembly.GetExecutingAssembly();
string comApiLocation = comApiAssembly.Location;
configuration = null;
configuration = ConfigurationManager.OpenExeConfiguration(comApiLocation);
var toLoadEnumberable = configuration.AppSettings.Settings.GetEnumerator();
while (toLoadEnumberable.MoveNext())
{
    var current = (KeyValueConfigurationElement)toLoadEnumberable.Current;
    ConfigurationManager.AppSettings.Add(current.Key, current.Value);
}

Ushbu konfiguratsiya ma'lumotiga ConfigurationManager ilovasida kerak bo'lishi kerak. NET MAQOMOTI LIB boshqa .NET Assemblies-ga qo'ng'iroq qilish uchun ishlatiladi. Boshqa .NET tuzilmalari konfiguratsiyani talab qiladi.

Oldindan rahmat.

0

1 javoblar

Men ba'zi yordam olishni muvaffaq bo'ldim MSDN forumlaridan .

Asosiy ishlatish o'rniga .Clear/.Add /. ConfigurationManager.AppSettings ilovasida o'chirib qo'ying. Agar mavjud bo'lsa yoki mavjud bo'lmasa, sozlamalarga kiraman va u kalit uchun qiymatni belgilayman:

ConfigurationManager.AppSettings["Key"] = "KeyValue";

This updates the ConfigurationManager.AppSettings. This is great because as I access parts of my application which are out of scope from the initial "ASP Classic" -> "COM API" call I am still able to get Application Settings from the ConfigurationManager.

Bularning barchasi bilan aytganda, men KonfiguratsiyaManager.ConnectionStringsni qanday tahrirlashni bilmayman.

ni ishlating. / qo'shing. / qo'shing. ConnectionStrings ustiga olib tashlang istisno yuz beradi >. Bu masala bo'yicha biron bir fikr bormi?

Qo'shimcha ma'lumotni topsam, ushbu javobni yangilayman.

As an update: To get around the ConnectionString settings not having my settings, I have implemented the Unity Container IoC framework. I use a Static instance to host the IoC container and resolve my instances that way.

Buni amalga oshirish orqali interfeyslarni MAQOMOTI API-da sinf turlariga qarshi saqlashim mumkin, ya'ni Konstruktsion parametrlarini Konstruktorga qarshi qo'yish orqali qabul qila olaman degan ma'noni anglatadi.

2
qo'shib qo'ydi