سؤال

عند تطوير موقع على VS2010/IIS 7.5 ، أستخدم نشر الويب لنشر الموقع من الجهاز إلى خادم موقع DEV.

يحتوي الموقع على حوالي 40 دليلًا افتراضيًا ، وأود إنشاء تلك الموجودة على الخادم أثناء النشر. هل هناك طريقة بسيطة للقيام بذلك؟

أفكر في كتابة تطبيق صغير من شأنه تحميل القائمة من ملف أو قاعدة بيانات وإنشاءها عند الطلب. تحتوي الدلائل على مسارات مادية مختلفة على جهاز التطوير الخاص بي عن خادم الويب ، الذي يلقي أيضًا مفتاحًا في الأعمال.

هل كانت مفيدة؟

المحلول

إذا كنت تستخدم MSBuild لنشر الويب الخاص بك ، فيمكنك كتابة CustomBuildTask في .NET يمكنك استخدامه لإنشاء دليلك الظاهري.

هناك الكثير من الموارد حول كيفية إنشاء مهمة بناء مخصصة واستهلاكها ، ولكن إليك الرمز الذي أستخدمه لإنشاء دليل افتراضي باستخدام مهمة بناء مخصصة:

public void CreateVirtualDirectory()
{

    DirectoryEntry oDE = new DirectoryEntry("IIS://" +
            this._strServerName + "/W3SVC/" + _webSiteID + "/Root");


    //Get Default Web Site
    DirectoryEntries oDC = oDE.Children;

    //Add row to schema
    DirectoryEntry oVirDir = oDC.Add(this._strVDirName,
                oDE.SchemaClassName.ToString());

    //Commit changes for Schema class File
    oVirDir.CommitChanges();


    //Set virtual directory to physical path
    oVirDir.Properties["Path"].Value = this._strPhysicalPath;

    //Set read access
    oVirDir.Properties["AccessRead"][0] = true;

    //Set the default docs
    oVirDir.Properties["EnableDefaultDoc"][0] = true;
    oVirDir.Properties["DefaultDoc"][0] = "default.aspx";

    //set the name
    oVirDir.Properties["AppFriendlyName"][0] = this._strVDirName;

    //do it
    oVirDir.Invoke("AppCreate", true);


    //set the application pool
    if (!string.IsNullOrEmpty(_strApplicationPool))
    {
        object[] param = { 0, _strApplicationPool, true };
        oVirDir.Invoke("AppCreate3", param);
        oVirDir.Properties["AppIsolated"][0] = "2";
    }

    //Save all the changes
    oVirDir.CommitChanges();
}

نصائح أخرى

لم أقم بأي برمجة مخصصة ضد WebDeploy ، لكنني رأيت إشارة إلى أن هناك واجهة برمجة تطبيقات لذلك. لا يمكنني العثور على وثائق رسمية عليه ، ولكن ربما يمكن أن يوفر تطبيق المدونة+نموذج بداية: Web Deploy API تطبيق الويب

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top