Skip to content

Commit 78029e5

Browse files
author
Jennifer Deigendesch
committed
Added example for static files
1 parent 9dae210 commit 78029e5

File tree

6 files changed

+33
-8
lines changed

6 files changed

+33
-8
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# ASP.NET Core Example
2-
This is an example of an REST API with ASP.NET Core v1.0, which is made via following tutorial:
3-
https://www.microsoft.com/germany/techwiese/know-how/video.aspx?id=msdn_de_67138)
2+
This is an example of an REST API with ASP.NET Core v1.0, which is made via following tutorials:
3+
Channel9: Creating REST API with ASP.NET Core (german): https://www.microsoft.com/germany/techwiese/know-how/video.aspx?id=msdn_de_67138
4+
Managing Static Files in ASP.NET Core: https://www.youtube.com/watch?v=n3rL0ekYEOM

src/ASPNETCoreExample/ASPNETCoreExample.xproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,5 @@
1919
<DnxInvisibleContent Include="bower.json" />
2020
<DnxInvisibleContent Include=".bowerrc" />
2121
</ItemGroup>
22-
<ItemGroup>
23-
<DnxInvisibleFolder Include="wwwroot\" />
24-
</ItemGroup>
2522
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" />
2623
</Project>

src/ASPNETCoreExample/Startup.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,28 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
2626
app.UseDeveloperExceptionPage();
2727
}
2828

29+
app.UseMvc();
30+
31+
DefaultFilesOptions options = CreateDefaultFilesOptions();
32+
app.UseDefaultFiles(options);
33+
app.UseFileServer();
34+
35+
InitMapper();
36+
}
37+
38+
private static DefaultFilesOptions CreateDefaultFilesOptions() {
39+
DefaultFilesOptions options = new DefaultFilesOptions();
40+
options.DefaultFileNames.Clear();
41+
options.DefaultFileNames.Add("MyIndex.html");
42+
43+
return options;
44+
}
45+
46+
private static void InitMapper() {
2947
AutoMapper.Mapper.Initialize(
3048
mapper => {
3149
mapper.CreateMap<FoodItem, FoodDto>().ReverseMap();
3250
});
33-
34-
app.UseMvc();
3551
}
3652
}
3753
}

src/ASPNETCoreExample/project.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"AutoMapper": "5.2.0",
1212
"Microsoft.AspNetCore.Mvc.Core": "1.0.1",
1313
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.1",
14-
"Microsoft.AspNetCore.Mvc": "1.0.1"
14+
"Microsoft.AspNetCore.Mvc": "1.0.1",
15+
"Microsoft.AspNetCore.StaticFiles": "1.1.0"
1516
},
1617

1718
"tools": {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8"/>
5+
<title></title>
6+
</head>
7+
<body>
8+
<h1>Hi, I'm a static file!</h1>
9+
</body>
10+
</html>
450 Bytes
Loading

0 commit comments

Comments
 (0)