I am trying to create a Kestrel web server which will serve static file from a local folder path ( eg: C:\Website). But my web server is not getting started or its not able to find the file. Giving below my code
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(@"C:\Website")
.UseStartup<Startup>()
.Build();
below is my Configure method
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(
@"C:\Website"),
RequestPath = "/StaticFiles"
});
}
but when i am trying to access my index.html file inside the folder with the url http://localhost:5000/StaticFiles/index.html it is not working . I am getting the error localhost didn’t send any data.ERR_EMPTY_RESPONSE . Is there any thing i am missing . When i run the application in debug mode i can see the below log in visual studio output window
Hosting environment: Production Content root path: C:\Website Now listening on: http://localhost:5000 Now listening on: https://localhost:5001 Application started. Press Ctrl+C to shut down.
Is there any other way to do this ?
Aucun commentaire:
Enregistrer un commentaire