默认情况下,提供静态文件index.html

时间:2015-11-19 03:21:05

标签: asp.net asp.net-core

我有一个非常简单的角度应用项目,只需要提供来自<?php $sql = "SELECT Course_name as name, Calories, Remarks, PictureID, Price, Ingredients, Description, Days FROM I_MAIN_COURSE"; $result = mysqli_query($con,$sql); if ($result->num_rows > 0) { // output data of each row print "<ul>"; while($row=mysqli_fetch_assoc($result)){ $n=$row['name']; $c=$row['Calories']; $i=$row['Ingredients']; $p=$row['Price']; $r=$row['Remarks']; $d=$row['Days']; $de=$row['Description']; $_SESSION["name"]=$n; print "<li>"; print "<p>Name:".$n."</p>"; print "<p>Calories: ".$c." cal</p>"; print "<p>Price: ".$p."</p>"; print "<p>Available Day: ".$d."</p>"; print "<p>Ingredients: ".$i."</p>"; print "<p>Description: ".$de."</p>"; print "<p>Remarks: ".$r."</p>"; ?> Quantity: <select class="lol" name = "quantity"> <option value = "0">0</option> <option value = "1">1</option> <option value = "2">2</option> <option value = "3">3</option> <option value = "4">4</option> <option value = "5">5</option> <option value = "6">6</option> <option value = "7">7</option> <option value = "8">8</option> <option value = "9">9</option> <option value = "10">10</option> </select> <button class="food" value="<?php echo $n ?>" > Add to Cart</button> </li> <?php $count++; } print "</ul>"; } ?> 的静态文件。这是我的wwwroot

Startup.cs

每当我使用IIS Express或Web启动项目时,我总是必须导航到public class Startup { public void ConfigureServices(IServiceCollection services) { } public void Configure(IApplicationBuilder app) { app.UseIISPlatformHandler(); app.UseStaticFiles(); } // Entry point for the application. public static void Main(string[] args) => WebApplication.Run<Startup>(args); } 。如何制作它以便我可以访问根(/index.html)并仍然获得/

2 个答案:

答案 0 :(得分:7)

您想要服务器默认文件和静态文件:

public void Configure(IApplicationBuilder application)
{
    ...
    // Enable serving of static files from the wwwroot folder.
    application.UseStaticFiles();
    // Serve the default file, if present.
    application.UseDefaultFiles();
    ...
}

或者,你可以使用UseFileServer方法,它使用一行而不是两行来做同样的事情。

public void Configure(IApplicationBuilder application)
{
    ...
    application.UseFileServer();
    ...
}

有关详细信息,请参阅documentation

答案 1 :(得分:6)

只需将app.UseStaticFiles();更改为app.UseFileServer();

即可
public class Startup
{
    public void ConfigureServices(IServiceCollection services) { }

    public void Configure(IApplicationBuilder app)
    {
        app.UseIISPlatformHandler();
        app.UseFileServer();
    }

    // Entry point for the application.
    public static void Main(string[] args) => WebApplication.Run<Startup>(args);
}