Skip to content
This repository was archived by the owner on Apr 23, 2023. It is now read-only.

Commit e62a999

Browse files
security website sample
1 parent d189f03 commit e62a999

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+23664
-44
lines changed
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "wwwroot/lib"
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
9+
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design">
10+
<Version>2.0.0</Version>
11+
</PackageReference>
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
16+
</ItemGroup>
17+
18+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore.Mvc;
7+
using ASPNETCoreMVCSecurity.Models;
8+
using Microsoft.AspNetCore.Html;
9+
using System.Net.Http.Headers;
10+
11+
namespace ASPNETCoreMVCSecurity.Controllers
12+
{
13+
public class HomeController : Controller
14+
{
15+
public string Echo(string x) => x;
16+
17+
public IActionResult EchoUnencoded(string x) => Content(x, "text/html");
18+
19+
public IActionResult EchoWithView(string x)
20+
{
21+
ViewBag.SampleData = x;
22+
return View();
23+
}
24+
25+
public IActionResult Index()
26+
{
27+
return View();
28+
}
29+
30+
public IActionResult About()
31+
{
32+
ViewData["Message"] = "Your application description page.";
33+
34+
return View();
35+
}
36+
37+
public IActionResult Contact()
38+
{
39+
ViewData["Message"] = "Your contact page.";
40+
41+
return View();
42+
}
43+
44+
public IActionResult Error()
45+
{
46+
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
47+
}
48+
49+
public IActionResult EditBook() => View();
50+
51+
[HttpPost]
52+
[ValidateAntiForgeryToken]
53+
public IActionResult EditBook(Book book) => View("EditBookResult", book);
54+
}
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace ASPNETCoreMVCSecurity.Models
7+
{
8+
public class Book
9+
{
10+
public string Title { get; set; }
11+
public string Publisher { get; set; }
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace ASPNETCoreMVCSecurity.Models
4+
{
5+
public class ErrorViewModel
6+
{
7+
public string RequestId { get; set; }
8+
9+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
10+
}
11+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace ASPNETCoreMVCSecurity
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
BuildWebHost(args).Run();
18+
}
19+
20+
public static IWebHost BuildWebHost(string[] args) =>
21+
WebHost.CreateDefaultBuilder(args)
22+
.UseStartup<Startup>()
23+
.Build();
24+
}
25+
}
+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Hosting;
7+
using Microsoft.Extensions.Configuration;
8+
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.AspNetCore.Http;
10+
using System.Text.Encodings.Web;
11+
12+
namespace ASPNETCoreMVCSecurity
13+
{
14+
public class Startup
15+
{
16+
public Startup(IConfiguration configuration)
17+
{
18+
Configuration = configuration;
19+
}
20+
21+
public IConfiguration Configuration { get; }
22+
23+
// This method gets called by the runtime. Use this method to add services to the container.
24+
public void ConfigureServices(IServiceCollection services)
25+
{
26+
services.AddMvc();
27+
}
28+
29+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
30+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
31+
{
32+
if (env.IsDevelopment())
33+
{
34+
app.UseDeveloperExceptionPage();
35+
app.UseBrowserLink();
36+
}
37+
else
38+
{
39+
app.UseExceptionHandler("/Home/Error");
40+
}
41+
42+
app.UseStaticFiles();
43+
44+
app.Map("/echo", app1 =>
45+
{
46+
app1.Run(async context =>
47+
{
48+
string data = context.Request.Query["x"];
49+
await context.Response.WriteAsync(data);
50+
});
51+
});
52+
53+
app.Map("/echoenc", app1 =>
54+
{
55+
app1.Run(async context =>
56+
{
57+
string data = context.Request.Query["x"];
58+
await context.Response.WriteAsync(HtmlEncoder.Default.Encode(data));
59+
});
60+
});
61+
62+
app.UseMvc(routes =>
63+
{
64+
routes.MapRoute(
65+
name: "default",
66+
template: "{controller=Home}/{action=Index}/{id?}");
67+
});
68+
}
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@{
2+
ViewData["Title"] = "About";
3+
}
4+
<h2>@ViewData["Title"]</h2>
5+
<h3>@ViewData["Message"]</h3>
6+
7+
<p>Use this area to provide additional information.</p>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@{
2+
ViewData["Title"] = "Contact";
3+
}
4+
<h2>@ViewData["Title"]</h2>
5+
<h3>@ViewData["Message"]</h3>
6+
7+
<address>
8+
One Microsoft Way<br />
9+
Redmond, WA 98052-6399<br />
10+
<abbr title="Phone">P:</abbr>
11+
425.555.0100
12+
</address>
13+
14+
<address>
15+
<strong>Support:</strong> <a href="mailto:[email protected]">Support@example.com</a><br />
16+
<strong>Marketing:</strong> <a href="mailto:[email protected]">Marketing@example.com</a>
17+
</address>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using Microsoft.AspNetCore.Html;
2+
@{
3+
Layout = null;
4+
}
5+
6+
<!DOCTYPE html>
7+
8+
<html>
9+
<head>
10+
<meta name="viewport" content="width=device-width" />
11+
<title>EchoWithView</title>
12+
</head>
13+
<body>
14+
@{
15+
string data = ViewBag.SampleData;
16+
}
17+
<div>
18+
this is encoded
19+
</div>
20+
<div>@data</div>
21+
22+
<br />
23+
<div>
24+
This is not encoded
25+
</div>
26+
<div>
27+
@Html.Raw(@data)
28+
</div>
29+
30+
31+
</body>
32+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
@{
3+
ViewData["Title"] = "EditBook";
4+
}
5+
<h2>Edit Book</h2>
6+
7+
8+
<form asp-controller="Home" asp-action="EditBook" method="post">
9+
@Html.AntiForgeryToken()
10+
11+
<label for="title">Title:</label>
12+
<input type="text" id="title" name="title" />
13+
<br />
14+
<label for="publisher">Publisher:</label>
15+
<input type="text" id="publisher" name="publisher" />
16+
<br />
17+
<input type="submit" value="Submit" />
18+
</form>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
2+
@{
3+
ViewData["Title"] = "EditBookResult";
4+
}
5+
6+
<h2>Book entered...</h2>
7+
8+
@Html.DisplayForModel()
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
@{
2+
ViewData["Title"] = "Home Page";
3+
}
4+
5+
<div id="myCarousel" class="carousel slide" data-ride="carousel" data-interval="6000">
6+
<ol class="carousel-indicators">
7+
<li data-target="#myCarousel" data-slide-to="0" class="active"></li>
8+
<li data-target="#myCarousel" data-slide-to="1"></li>
9+
<li data-target="#myCarousel" data-slide-to="2"></li>
10+
<li data-target="#myCarousel" data-slide-to="3"></li>
11+
</ol>
12+
<div class="carousel-inner" role="listbox">
13+
<div class="item active">
14+
<img src="~/images/banner1.svg" alt="ASP.NET" class="img-responsive" />
15+
<div class="carousel-caption" role="option">
16+
<p>
17+
Learn how to build ASP.NET apps that can run anywhere.
18+
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525028&clcid=0x409">
19+
Learn More
20+
</a>
21+
</p>
22+
</div>
23+
</div>
24+
<div class="item">
25+
<img src="~/images/banner2.svg" alt="Visual Studio" class="img-responsive" />
26+
<div class="carousel-caption" role="option">
27+
<p>
28+
There are powerful new features in Visual Studio for building modern web apps.
29+
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525030&clcid=0x409">
30+
Learn More
31+
</a>
32+
</p>
33+
</div>
34+
</div>
35+
<div class="item">
36+
<img src="~/images/banner3.svg" alt="Package Management" class="img-responsive" />
37+
<div class="carousel-caption" role="option">
38+
<p>
39+
Bring in libraries from NuGet, Bower, and npm, and automate tasks using Grunt or Gulp.
40+
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525029&clcid=0x409">
41+
Learn More
42+
</a>
43+
</p>
44+
</div>
45+
</div>
46+
<div class="item">
47+
<img src="~/images/banner4.svg" alt="Microsoft Azure" class="img-responsive" />
48+
<div class="carousel-caption" role="option">
49+
<p>
50+
Learn how Microsoft's Azure cloud platform allows you to build, deploy, and scale web apps.
51+
<a class="btn btn-default" href="https://go.microsoft.com/fwlink/?LinkID=525027&clcid=0x409">
52+
Learn More
53+
</a>
54+
</p>
55+
</div>
56+
</div>
57+
</div>
58+
<a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
59+
<span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
60+
<span class="sr-only">Previous</span>
61+
</a>
62+
<a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
63+
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
64+
<span class="sr-only">Next</span>
65+
</a>
66+
</div>
67+
68+
<div class="row">
69+
<div class="col-md-3">
70+
<h2>Application uses</h2>
71+
<ul>
72+
<li>Sample pages using ASP.NET Core MVC</li>
73+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=518004">Bower</a> for managing client-side libraries</li>
74+
<li>Theming using <a href="https://go.microsoft.com/fwlink/?LinkID=398939">Bootstrap</a></li>
75+
</ul>
76+
</div>
77+
<div class="col-md-3">
78+
<h2>How to</h2>
79+
<ul>
80+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=398600">Add a Controller and View</a></li>
81+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699315">Manage User Secrets using Secret Manager.</a></li>
82+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699316">Use logging to log a message.</a></li>
83+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699317">Add packages using NuGet.</a></li>
84+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699318">Add client packages using Bower.</a></li>
85+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699319">Target development, staging or production environment.</a></li>
86+
</ul>
87+
</div>
88+
<div class="col-md-3">
89+
<h2>Overview</h2>
90+
<ul>
91+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=518008">Conceptual overview of what is ASP.NET Core</a></li>
92+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=699320">Fundamentals of ASP.NET Core such as Startup and middleware.</a></li>
93+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=398602">Working with Data</a></li>
94+
<li><a href="https://go.microsoft.com/fwlink/?LinkId=398603">Security</a></li>
95+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699321">Client side development</a></li>
96+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699322">Develop on different platforms</a></li>
97+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=699323">Read more on the documentation site</a></li>
98+
</ul>
99+
</div>
100+
<div class="col-md-3">
101+
<h2>Run &amp; Deploy</h2>
102+
<ul>
103+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=517851">Run your app</a></li>
104+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=517853">Run tools such as EF migrations and more</a></li>
105+
<li><a href="https://go.microsoft.com/fwlink/?LinkID=398609">Publish to Microsoft Azure Web Apps</a></li>
106+
</ul>
107+
</div>
108+
</div>

0 commit comments

Comments
 (0)