将Blazor应用程序部署到IIS子应用程序

时间:2020-05-26 16:22:52

标签: c# asp.net-core iis path blazor

我正在尝试将Blazor Server应用程序部署在/ app下,该应用程序是IIS中的子应用程序。我在网上的几个地方都读过,需要设置以下内容:

public class Main {

public static void main(String[] args) throws IOException, InterruptedException {

    //To input the user's search
    Scanner nw1 = new Scanner(System.in);
    System.out.println("What do you want to search?");
    String a = nw1.nextLine();

    //Open the driver
    System.setProperty("webdriver.chrome.driver", 
    "E:\\JetBrains\\webdriver\\chrome\\chromedriver.exe");
    WebDriver AE = new ChromeDriver();

    //Open the web page and Login in.
    AE.get("https://www.aliexpress.com/");
    Thread.sleep(2000);

    //xpath of account button
    AE.findElement(By.xpath("//*[@id="nav-user-account"]/div/div/p[3]/a[2]")).click();

    //xpath of Sign in button
    AE.findElement(By.xpath("/html/body/div[9]/a")).click();
    AE.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    //xpath of Email box 
    AE.findElement(By.xpath("//*[@id=\"fm-login-id\"]")).sendKeys("my-email");

    //xpath of password section to type  
    AE.findElement(By.xpath("//*[@id=\'fm-login-password\']")).sendKeys("my-password");
    AE.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    // xpath of submit button
    AE.findElement(By.xpath("//*[@id="login-form"]/div[5]/button")).click()

Startup.cs | app.UsePathBase("/app")

但是当我运行它时,出现以下错误:

_Host.cshtml | <base href="~/app/" />

如果我更改为(不带斜杠)

blazor.server.js:15 [2020-05-26T16:16:11.796Z] Error: The circuit failed to initialize.
e.log @ blazor.server.js:15
blazor.server.js:1 [2020-05-26T16:16:11.798Z] Information: Connection disconnected.
blazor.server.js:1 Uncaught (in promise) Error: Invocation canceled due to the underlying connection being closed.
    at e.connectionClosed (blazor.server.js:1)
    at e.connection.onclose (blazor.server.js:1)
    at e.stopConnection (blazor.server.js:1)
    at e.transport.onclose (blazor.server.js:1)
    at e.close (blazor.server.js:1)
    at e.stop (blazor.server.js:1)
    at e.<anonymous> (blazor.server.js:1)
    at blazor.server.js:1
    at Object.next (blazor.server.js:1)
    at a (blazor.server.js:1)

该应用程序正在运行,但URL之前没有任何/ app(据我所知没有任何变化)。

在某些示例中,我看到他们更改了BlazorHub路径,但我无法使其正常工作。其背后的原因是能够将应用程序和登录页面作为单独的IIS站点进行托管。

1 个答案:

答案 0 :(得分:0)

这对我们有用: <base href="/app/" />

注意结尾的斜杠,这很重要。

它在官方Blazor文档中有记录,https://docs.microsoft.com/en-us/aspnet/core/blazor/host-and-deploy/?view=aspnetcore-3.1&tabs=visual-studio#app-base-path