【问题标题】:How to create an exe for a web application?如何为 Web 应用程序创建 exe?
【发布时间】:2013-02-07 10:19:27
【问题描述】:

我使用 Visual Studio 2012 (ASP.Net 4.5 - C#) 和 Web 服务开发了一个 Web 应用程序。两者都在一个单一的解决方案中。我需要将我的解决方案转换为 EXE 文件(为我的 Web 应用程序创建 EXE)。我真正需要的是,如果运行我的设置文件,它应该在 IIS 中托管我的 Web 应用程序和 Web 服务。请提供解决问题的步骤。

【问题讨论】:

  • 你的问题真的不清楚。您已经构建了一个 Web 应用程序,但您想将其作为可执行文件分发?这实际上是不可能的,但您可以使用兼容的 Web 服务器(例如 IISExpress)分发它。不过,请您澄清一下您的要求,因为目前它们没有什么意义。
  • @RB。我在一个解决方案文件下有一个 Web 应用程序和一个 Web 服务。现在我们需要不同的端口和虚拟目录来访问这些应用程序和服务。为了避免这种情况,我需要创建一个 EXE,它应该包含我的应用程序和服务。
  • 您声明您需要不同的端口和虚拟目录来访问您的应用程序/服务。我不明白*.exe 文件与这个问题有什么关系。请编辑您的问题以完整解释您的问题,以及为什么您认为让您的应用程序可从 EXE 启动将解决此问题。
  • @RB。感谢您的回复,我现在编辑了我的问题。我使用“InstallShield”(它是第 3 方工具)创建了一个安装文件。现在正在运行安装程序,它在 Visual Studio 屏幕中打开,而不是在浏览器中运行。
  • @RB。当我安装此设置时,它显示警告“此设置是使用 InstallShield 的评估版本创建的”。最后我的要求是,当我运行设置时,应用程序应该托管在 IIS 中

标签: asp.net web-applications exe


【解决方案1】:

安静的迟到的答案: 我无法在此处发布整个项目,但我会在此处发布流程图,您可以尝试一下。

此处流程图中的所有步骤都应以编程方式控制。

1.启动应用程序的步骤。

注意:如果您使用的是本地数据库(.mdf),请忽略第三层(是否添加了网站)

用于本地数据库的连接字符串:

public string ConnectionString =
            "Data Source=(local);Initial Catalog=YOUR_DATABASE_NAME;Integrated Security=True";

但请记住,您需要安装 dotnet 框架才能运行您的应用程序。不用担心,您可以在应用程序设置项目中设置先决条件。

下面的流程图过程的所有代码。

是否安装了 IIS

注意:我正在发布 IIS 7 及更高版本的代码。

public bool IsIISInstalled()
        {
            return Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\InetStp",
                "VersionString", null) != null;
        }

安装 IIS

public int InstallIIS()
        {
            string DISM_CMD_CODE = "START /WAIT DISM /Online /Enable-Feature /FeatureName:IIS-ApplicationDevelopment /FeatureName:IIS-ASP /FeatureName:IIS-ASPNET /FeatureName:IIS-BasicAuthentication /FeatureName:IIS-CGI /FeatureName:IIS-ClientCertificateMappingAuthentication /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-CustomLogging /FeatureName:IIS-DefaultDocument /FeatureName:IIS-DigestAuthentication /FeatureName:IIS-DirectoryBrowsing /FeatureName:IIS-FTPExtensibility /FeatureName:IIS-FTPServer /FeatureName:IIS-FTPSvc /FeatureName:IIS-HealthAndDiagnostics /FeatureName:IIS-HostableWebCore /FeatureName:IIS-HttpCompressionDynamic /FeatureName:IIS-HttpCompressionStatic /FeatureName:IIS-HttpErrors /FeatureName:IIS-HttpLogging /FeatureName:IIS-HttpRedirect /FeatureName:IIS-HttpTracing /FeatureName:IIS-IIS6ManagementCompatibility /FeatureName:IIS-IISCertificateMappingAuthentication /FeatureName:IIS-IPSecurity /FeatureName:IIS-ISAPIExtensions /FeatureName:IIS-ISAPIFilter /FeatureName:IIS-LegacyScripts /FeatureName:IIS-LegacySnapIn /FeatureName:IIS-LoggingLibraries /FeatureName:IIS-ManagementConsole /FeatureName:IIS-ManagementScriptingTools /FeatureName:IIS-ManagementService /FeatureName:IIS-Metabase /FeatureName:IIS-NetFxExtensibility /FeatureName:IIS-ODBCLogging /FeatureName:IIS-Performance /FeatureName:IIS-RequestFiltering /FeatureName:IIS-RequestMonitor /FeatureName:IIS-Security /FeatureName:IIS-ServerSideIncludes /FeatureName:IIS-StaticContent /FeatureName:IIS-URLAuthorization /FeatureName:IIS-WebDAV /FeatureName:IIS-WebServer /FeatureName:IIS-WebServerManagementTools /FeatureName:IIS-WebServerRole /FeatureName:IIS-WindowsAuthentication /FeatureName:IIS-WMICompatibility /FeatureName:WAS-ConfigurationAPI /FeatureName:WAS-NetFxEnvironment /FeatureName:WAS-ProcessModel /FeatureName:WAS-WindowsActivationService";
            string command = DISM_CMD_CODE;
            ProcessStartInfo pStartInfo = new ProcessStartInfo("cmd.exe", "/c " + command);
            Process p = new Process();
            p.StartInfo = pStartInfo;
            //p.WaitForExit();
            p.Start();
            return 1;
        }

是否添加了网站

public bool IsWebsiteAddedInIIS(string WebsiteName)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == WebsiteName);
            if (site == null)
            {
                //No site added
                return false;
            }
            else
            {
                //site added
                return true;
            }
        }

public int CreateNewWebsite(string SiteName, string PublishedFilesPath)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            if (site == null)
            {
                serverManager.Sites.Add(SiteName, "http", "*:8080:", PublishedFilesPath);
                serverManager.CommitChanges();
                return 1;
            }
            else
            {
                return 2;
            }
        }

public void StartWebsite(string SiteName)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            if (site != null)
            {
                site.Stop();
                site.Start();
            }
        }

        public void StopWebsite(string SiteName)
        {
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            if (site != null)
            {
                site.Stop();
            }
        }

获取网站网址

public string GetWebsiteURL(string SiteName)
        {
            //string SiteUrl = "";
            //ServerManager serverManager = new ServerManager();
            //var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            //var siteBindings = site.GetCollection("bindings");
            //string protocol = (string)siteBindings["protocol"];
            //string bindingInfo = (string)siteBindings["bindingInformation"];
            //if (protocol.StartsWith("http", StringComparison.OrdinalIgnoreCase))
            //{
            //    string[] parts = bindingInfo.Split(':');
            //    if (parts.Length == 3)
            //    {
            //        //Get the port in use HERE !!!
            //        string port = parts[1];
            //        SiteUrl = "localhost:" + port;
            //    }
            //}
            //return SiteUrl;

            int port = 0;
            string SiteUrl = "";
            ServerManager serverManager = new ServerManager();
            var site = serverManager.Sites.FirstOrDefault(s => s.Name == SiteName);
            foreach (Binding binding in site.Bindings)
            {
                port = binding.EndPoint.Port;
                SiteUrl = "localhost:" + port + "/index.aspx";
                break;
            }
            return SiteUrl;
        }

初始化浏览网站

您必须将 Cefsharp chromium 浏览器安装到您的 windows 窗体中

安装包 CefSharp.WinForms -版本 75.1.143

public void InitBrowser(string Address)
        {
            Cef.Initialize(new CefSettings());
            browser = new ChromiumWebBrowser(Address);
            Controls.Add(browser);
            browser.Dock = DockStyle.Fill;
        }

谢谢你..

【讨论】:

    【解决方案2】:

    也许您需要创建一个网络设置项目。 “一个 Web 设置项目提供了 部署网站的最高灵活性。虽然 Web 设置项目更多 对于开发人员来说很复杂,它们允许您生成 MSI 包,预编译网站, 并执行您的应用程序可能需要的几乎所有设置任务。

    许多网站不需要自定义配置。在这些情况下,您可以简单地构建 您的 MSI 文件并准备好部署。但是,更复杂的场景包括依赖项 (例如特定的操作系统版本或服务包)、自定义注册表项、 或管理员配置。 Web 设置项目允许您部署满足 这些要求。”

    查看第 8 章“调试和部署”中的“MCTS 自定进度培训工具包(考试 70-515)- 使用 Microsoft .NET Framework 4 进行 Web 应用程序开发”一书。

    希望这会有所帮助。

    【讨论】:

    • 感谢您的回复我现在编辑了我的问题。我使用“InstallShield”(它是第 3 方工具)创建了一个安装文件。当我安装此设置时,它显示警告“此设置是使用 InstallShield 的评估版本创建的”。最后我的要求是,当我运行安装程序时,应用程序应该托管在 IIS 中。请帮我解决这个问题。
    猜你喜欢
    • 1970-01-01
    • 2018-04-24
    • 2015-05-01
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多