MVC functional test cleanup (part 1)

- #3612 subpart 2 of 2
- merge `ActionConstraintsWebSite`, `AntiforgeryTokenWebSite` and `ContentNegotiationWebSite` into `BasicWebSite`
  - remove tests depending on `ErrorReporterMiddleware` in merged sites; not used in `BasicWebSite`
- delete `CompositeViewEngineWebSite`, `Microsoft.AspNet.Mvc.ViewEngines.CompositeViewEngineTest` covers cases
- delete `CorsMiddlewareWebsite`, soon to be in Cors repo (see aspnet/CORS#57)
- remove `SendFileMiddleware` from FilesWebSite, unused there
This commit is contained in:
Doug Bunting 2015-12-13 21:57:30 -08:00
parent 1b7e67211f
commit 59824dc7be
83 changed files with 142 additions and 1059 deletions

73
Mvc.sln
View File

@ -44,8 +44,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
global.json = global.json
EndProjectSection
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ContentNegotiationWebSite", "test\WebSites\ContentNegotiationWebSite\ContentNegotiationWebSite.xproj", "{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "FiltersWebSite", "test\WebSites\FiltersWebSite\FiltersWebSite.xproj", "{1976AC4A-FEA4-4587-A158-D9F79736D2B6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ApiExplorerWebSite", "test\WebSites\ApiExplorerWebSite\ApiExplorerWebSite.xproj", "{61061528-071E-424E-965A-07BCC2F02672}"
@ -74,14 +72,10 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TagHel
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PrecompilationWebSite", "test\WebSites\PrecompilationWebSite\PrecompilationWebSite.xproj", "{59E1BE90-92C1-4D35-ADCC-B69F49077C81}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CompositeViewEngineWebSite", "test\WebSites\CompositeViewEngineWebSite\CompositeViewEngineWebSite.xproj", "{A853B2BA-4449-4908-A416-5A3C027FC22B}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "HtmlGenerationWebSite", "test\WebSites\HtmlGenerationWebSite\HtmlGenerationWebSite.xproj", "{920F8A0E-6F7D-4BBE-84FF-840B89099BE6}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ErrorPageMiddlewareWebSite", "test\WebSites\ErrorPageMiddlewareWebSite\ErrorPageMiddlewareWebSite.xproj", "{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ActionConstraintsWebSite", "test\WebSites\ActionConstraintsWebSite\ActionConstraintsWebSite.xproj", "{AF210F69-9D31-43AF-AC3A-CD366E252218}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "XmlFormattersWebSite", "test\WebSites\XmlFormattersWebSite\XmlFormattersWebSite.xproj", "{C3123A70-41C4-4122-AD1C-D35DF8958DD7}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "ControllersFromServicesWebSite", "test\WebSites\ControllersFromServicesWebSite\ControllersFromServicesWebSite.xproj", "{983741B2-4424-4ED1-9B03-7675A67230C8}"
@ -94,8 +88,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TestCo
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CorsWebSite", "test\WebSites\CorsWebSite\CorsWebSite.xproj", "{94BA134D-04B3-48AA-BA55-5A4DB8640F2D}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CorsMiddlewareWebSite", "test\WebSites\CorsMiddlewareWebSite\CorsMiddlewareWebSite.xproj", "{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.IntegrationTests", "test\Microsoft.AspNet.Mvc.IntegrationTests\Microsoft.AspNet.Mvc.IntegrationTests.xproj", "{864FA09D-1E48-403A-A6C8-4F079D2A30F0}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Abstractions", "src\Microsoft.AspNet.Mvc.Abstractions\Microsoft.AspNet.Mvc.Abstractions.xproj", "{1154203C-7579-4525-906E-BC55268421C1}"
@ -106,8 +98,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ApiExp
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.Abstractions.Test", "test\Microsoft.AspNet.Mvc.Abstractions.Test\Microsoft.AspNet.Mvc.Abstractions.Test.xproj", "{DA000953-7532-4DF5-8DB9-8143DF98D999}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "AntiforgeryTokenWebSite", "test\WebSites\AntiforgeryTokenWebSite\AntiforgeryTokenWebSite.xproj", "{A353B17E-A940-4CE8-8BF9-179E24A9041F}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "MvcMinimalSample.Web", "samples\MvcMinimalSample.Web\MvcMinimalSample.Web.xproj", "{F21E225B-190B-4DAA-8B0A-05986D231F56}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.ViewFeatures", "src\Microsoft.AspNet.Mvc.ViewFeatures\Microsoft.AspNet.Mvc.ViewFeatures.xproj", "{3F8B8FC1-9FE4-4788-8991-367113E8D7AD}"
@ -302,16 +292,6 @@ Global
{62735776-46FF-4170-9392-02E128A69B89}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{62735776-46FF-4170-9392-02E128A69B89}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{62735776-46FF-4170-9392-02E128A69B89}.Release|x86.ActiveCfg = Release|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Debug|x86.ActiveCfg = Debug|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|Any CPU.Build.0 = Release|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7}.Release|x86.ActiveCfg = Release|Any CPU
{1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1976AC4A-FEA4-4587-A158-D9F79736D2B6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -452,18 +432,6 @@ Global
{59E1BE90-92C1-4D35-ADCC-B69F49077C81}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{59E1BE90-92C1-4D35-ADCC-B69F49077C81}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{59E1BE90-92C1-4D35-ADCC-B69F49077C81}.Release|x86.ActiveCfg = Release|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Debug|x86.ActiveCfg = Debug|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Debug|x86.Build.0 = Debug|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|Any CPU.Build.0 = Release|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|x86.ActiveCfg = Release|Any CPU
{A853B2BA-4449-4908-A416-5A3C027FC22B}.Release|x86.Build.0 = Release|Any CPU
{920F8A0E-6F7D-4BBE-84FF-840B89099BE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{920F8A0E-6F7D-4BBE-84FF-840B89099BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{920F8A0E-6F7D-4BBE-84FF-840B89099BE6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -488,18 +456,6 @@ Global
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}.Release|x86.ActiveCfg = Release|Any CPU
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718}.Release|x86.Build.0 = Release|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Debug|x86.ActiveCfg = Debug|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Debug|x86.Build.0 = Debug|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Release|Any CPU.Build.0 = Release|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Release|x86.ActiveCfg = Release|Any CPU
{AF210F69-9D31-43AF-AC3A-CD366E252218}.Release|x86.Build.0 = Release|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C3123A70-41C4-4122-AD1C-D35DF8958DD7}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -571,18 +527,6 @@ Global
{94BA134D-04B3-48AA-BA55-5A4DB8640F2D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{94BA134D-04B3-48AA-BA55-5A4DB8640F2D}.Release|x86.ActiveCfg = Release|Any CPU
{94BA134D-04B3-48AA-BA55-5A4DB8640F2D}.Release|x86.Build.0 = Release|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Debug|x86.ActiveCfg = Debug|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Debug|x86.Build.0 = Debug|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Release|Any CPU.Build.0 = Release|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Release|x86.ActiveCfg = Release|Any CPU
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB}.Release|x86.Build.0 = Release|Any CPU
{864FA09D-1E48-403A-A6C8-4F079D2A30F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{864FA09D-1E48-403A-A6C8-4F079D2A30F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{864FA09D-1E48-403A-A6C8-4F079D2A30F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -643,18 +587,6 @@ Global
{DA000953-7532-4DF5-8DB9-8143DF98D999}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{DA000953-7532-4DF5-8DB9-8143DF98D999}.Release|x86.ActiveCfg = Release|Any CPU
{DA000953-7532-4DF5-8DB9-8143DF98D999}.Release|x86.Build.0 = Release|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Debug|x86.ActiveCfg = Debug|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Debug|x86.Build.0 = Debug|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Release|Any CPU.Build.0 = Release|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Release|x86.ActiveCfg = Release|Any CPU
{A353B17E-A940-4CE8-8BF9-179E24A9041F}.Release|x86.Build.0 = Release|Any CPU
{F21E225B-190B-4DAA-8B0A-05986D231F56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F21E225B-190B-4DAA-8B0A-05986D231F56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F21E225B-190B-4DAA-8B0A-05986D231F56}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -939,7 +871,6 @@ Global
{5F945B82-FE5F-425C-956C-8BC2F2020254} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{B07CAF59-11ED-40E3-A5DB-E1178F84FA78} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{62735776-46FF-4170-9392-02E128A69B89} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{C6E5AFFA-890A-448F-8DE3-878B1D3C9FC7} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{1976AC4A-FEA4-4587-A158-D9F79736D2B6} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{61061528-071E-424E-965A-07BCC2F02672} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{C6304029-78C8-4604-99BE-2078DCA1DD36} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
@ -954,23 +885,19 @@ Global
{B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{860119ED-3DB1-424D-8D0A-30132A8A7D96} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{59E1BE90-92C1-4D35-ADCC-B69F49077C81} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{A853B2BA-4449-4908-A416-5A3C027FC22B} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{920F8A0E-6F7D-4BBE-84FF-840B89099BE6} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{AD545A5B-2BA5-4314-88AC-FC2ACF2CC718} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{AF210F69-9D31-43AF-AC3A-CD366E252218} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{C3123A70-41C4-4122-AD1C-D35DF8958DD7} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{983741B2-4424-4ED1-9B03-7675A67230C8} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{551DC89E-2A13-4CF2-83D7-1ADD802443D5} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{C651F432-4EBE-41A6-BAD2-3E07CCBA209C} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{94BA134D-04B3-48AA-BA55-5A4DB8640F2D} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{B42D4844-FFF8-4EC2-88D1-3AE95234D9EB} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{864FA09D-1E48-403A-A6C8-4F079D2A30F0} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{1154203C-7579-4525-906E-BC55268421C1} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{A2B72833-5D70-4C42-AE85-E0319926FB8A} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{4C2AD8AB-8AC0-46C4-80C6-C5577C7255F6} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{DA000953-7532-4DF5-8DB9-8143DF98D999} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{A353B17E-A940-4CE8-8BF9-179E24A9041F} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{F21E225B-190B-4DAA-8B0A-05986D231F56} = {DAAE4C74-D06F-4874-A166-33305D2643CE}
{3F8B8FC1-9FE4-4788-8991-367113E8D7AD} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{3FC8D9D6-9352-43A3-8E81-422F270085B7} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}

View File

@ -10,9 +10,9 @@ using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class AntiforgeryTests : IClassFixture<MvcTestFixture<AntiforgeryTokenWebSite.Startup>>
public class AntiforgeryTests : IClassFixture<MvcTestFixture<BasicWebSite.Startup>>
{
public AntiforgeryTests(MvcTestFixture<AntiforgeryTokenWebSite.Startup> fixture)
public AntiforgeryTests(MvcTestFixture<BasicWebSite.Startup> fixture)
{
Client = fixture.Client;
}
@ -23,7 +23,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
public async Task MultipleAFTokensWithinTheSamePage_GeneratesASingleCookieToken()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/Account/Login");
var response = await Client.GetAsync("http://localhost/Antiforgery/Login");
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
@ -42,15 +42,17 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
// Arrange
// Do a get request.
var getResponse = await Client.GetAsync("http://localhost/Account/Login");
var getResponse = await Client.GetAsync("http://localhost/Antiforgery/Login");
var responseBody = await getResponse.Content.ReadAsStringAsync();
// Get the AF token for the second login. If the cookies are generated twice(i.e are different),
// this AF token will not work with the first cookie.
var formToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(responseBody, "Account/UseFacebookLogin");
var formToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(
responseBody,
"/Antiforgery/UseFacebookLogin");
var cookieToken = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse);
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/Login");
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Antiforgery/Login");
request.Headers.Add("Cookie", cookieToken.Key + "=" + cookieToken.Value);
var nameValueCollection = new List<KeyValuePair<string, string>>
{
@ -69,159 +71,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
Assert.Equal("OK", await response.Content.ReadAsStringAsync());
}
[Fact]
public async Task InvalidCookieToken_Throws()
{
// Arrange
var getResponse = await Client.GetAsync("http://localhost/Account/Login");
var responseBody = await getResponse.Content.ReadAsStringAsync();
var formToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(responseBody, "Account/Login");
var cookieToken = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse);
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/Login");
request.Headers.Add("Cookie", cookieToken.Key + "=invalidCookie");
var nameValueCollection = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("__RequestVerificationToken", formToken),
new KeyValuePair<string,string>("UserName", "abra"),
new KeyValuePair<string,string>("Password", "cadabra"),
};
request.Content = new FormUrlEncodedContent(nameValueCollection);
// Act
var response = await Client.SendAsync(request);
// Assert
var exception = response.GetServerException();
Assert.Equal("The antiforgery token could not be decrypted.", exception.ExceptionMessage);
}
[Fact]
public async Task InvalidFormToken_Throws()
{
// Arrange
var getResponse = await Client.GetAsync("http://localhost/Account/Login");
var responseBody = await getResponse.Content.ReadAsStringAsync();
var cookieToken = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse);
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/Login");
var formToken = "adsad";
request.Headers.Add("Cookie", cookieToken.Key + "=" + cookieToken.Value);
var nameValueCollection = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("__RequestVerificationToken", formToken),
new KeyValuePair<string,string>("UserName", "abra"),
new KeyValuePair<string,string>("Password", "cadabra"),
};
request.Content = new FormUrlEncodedContent(nameValueCollection);
// Act
var response = await Client.SendAsync(request);
// Assert
var exception = response.GetServerException();
Assert.Equal("The antiforgery token could not be decrypted.", exception.ExceptionMessage);
}
[Fact]
public async Task IncompatibleCookieToken_Throws()
{
// Arrange
// do a get response.
// We do two requests to get two different sets of antiforgery cookie and token values.
var getResponse1 = await Client.GetAsync("http://localhost/Account/Login");
var responseBody1 = await getResponse1.Content.ReadAsStringAsync();
var formToken1 = AntiforgeryTestHelper.RetrieveAntiforgeryToken(responseBody1, "Account/Login");
var getResponse2 = await Client.GetAsync("http://localhost/Account/Login");
var responseBody2 = await getResponse2.Content.ReadAsStringAsync();
var cookieToken2 = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse2);
var cookieToken = cookieToken2.Value;
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/Login");
request.Headers.Add("Cookie", string.Format("{0}={1}", cookieToken2.Key, cookieToken2.Value));
var formToken = formToken1;
var nameValueCollection = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("__RequestVerificationToken", formToken),
new KeyValuePair<string,string>("UserName", "abra"),
new KeyValuePair<string,string>("Password", "cadabra"),
};
request.Content = new FormUrlEncodedContent(nameValueCollection);
// Act
var response = await Client.SendAsync(request);
// Assert
var exception = response.GetServerException();
Assert.Equal("The antiforgery cookie token and form field token do not match.", exception.ExceptionMessage);
}
[Fact]
public async Task MissingCookieToken_Throws()
{
// Arrange
// do a get response.
var getResponse = await Client.GetAsync("http://localhost/Account/Login");
var responseBody = await getResponse.Content.ReadAsStringAsync();
var formToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(responseBody, "Account/Login");
var cookieTokenKey = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse).Key;
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/Login");
var nameValueCollection = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("__RequestVerificationToken", formToken),
new KeyValuePair<string,string>("UserName", "abra"),
new KeyValuePair<string,string>("Password", "cadabra"),
};
request.Content = new FormUrlEncodedContent(nameValueCollection);
// Act
var response = await Client.SendAsync(request);
// Assert
var exception = response.GetServerException();
Assert.Equal(
"The required antiforgery cookie \"" + cookieTokenKey + "\" is not present.",
exception.ExceptionMessage);
}
[Fact]
public async Task MissingAFToken_Throws()
{
// Arrange
var getResponse = await Client.GetAsync("http://localhost/Account/Login");
var responseBody = await getResponse.Content.ReadAsStringAsync();
var cookieToken = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse);
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/Login");
request.Headers.Add("Cookie", cookieToken.Key + "=" + cookieToken.Value);
var nameValueCollection = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string,string>("UserName", "abra"),
new KeyValuePair<string,string>("Password", "cadabra"),
};
request.Content = new FormUrlEncodedContent(nameValueCollection);
// Act
var response = await Client.SendAsync(request);
// Assert
var exception = response.GetServerException();
Assert.Equal("The required antiforgery form field \"__RequestVerificationToken\" is not present.",
exception.ExceptionMessage);
}
[Fact]
public async Task SetCookieAndHeaderBeforeFlushAsync_GeneratesCookieTokenAndHeader()
{
// Arrange & Act
var response = await Client.GetAsync("http://localhost/Account/FlushAsyncLogin");
var response = await Client.GetAsync("http://localhost/Antiforgery/FlushAsyncLogin");
// Assert
var header = Assert.Single(response.Headers.GetValues("X-Frame-Options"));
@ -236,13 +90,15 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
// Arrange
// do a get response.
var getResponse = await Client.GetAsync("http://localhost/Account/FlushAsyncLogin");
var getResponse = await Client.GetAsync("http://localhost/Antiforgery/FlushAsyncLogin");
var responseBody = await getResponse.Content.ReadAsStringAsync();
var formToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(responseBody, "Account/FlushAsyncLogin");
var formToken = AntiforgeryTestHelper.RetrieveAntiforgeryToken(
responseBody,
"Antiforgery/FlushAsyncLogin");
var cookieToken = AntiforgeryTestHelper.RetrieveAntiforgeryCookie(getResponse);
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Account/FlushAsyncLogin");
var request = new HttpRequestMessage(HttpMethod.Post, "http://localhost/Antiforgery/FlushAsyncLogin");
request.Headers.Add("Cookie", cookieToken.Key + "=" + cookieToken.Value);
var nameValueCollection = new List<KeyValuePair<string, string>>
{

View File

@ -1,39 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Net.Http;
using System.Threading.Tasks;
using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class CompositeViewEngineTests : IClassFixture<MvcTestFixture<CompositeViewEngineWebSite.Startup>>
{
public CompositeViewEngineTests(MvcTestFixture<CompositeViewEngineWebSite.Startup> fixture)
{
Client = fixture.Client;
}
public HttpClient Client { get; }
[Fact]
public async Task CompositeViewEngine_FindsPartialViewsAcrossAllEngines()
{
// Arrange & Act
var body = await Client.GetStringAsync("http://localhost/");
// Assert
Assert.Equal("Hello world", body.Trim());
}
[Fact]
public async Task CompositeViewEngine_FindsViewsAcrossAllEngines()
{
// Arrange & Act
var body = await Client.GetStringAsync("http://localhost/Home/TestView");
// Assert
Assert.Equal("Content from test view", body.Trim());
}
}
}

View File

@ -5,7 +5,7 @@ using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using ActionConstraintsWebSite;
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Testing.xunit;
using Newtonsoft.Json;
@ -13,9 +13,9 @@ using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class ConsumesAttributeTests : IClassFixture<MvcTestFixture<ActionConstraintsWebSite.Startup>>
public class ConsumesAttributeTests : IClassFixture<MvcTestFixture<BasicWebSite.Startup>>
{
public ConsumesAttributeTests(MvcTestFixture<ActionConstraintsWebSite.Startup> fixture)
public ConsumesAttributeTests(MvcTestFixture<BasicWebSite.Startup> fixture)
{
Client = fixture.Client;
}
@ -39,31 +39,6 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
Assert.Null(product);
}
[Fact]
public async Task NoRequestContentType_Throws_IfMultipleActionsWithConstraints()
{
// Arrange
var request = new HttpRequestMessage(
HttpMethod.Post,
"http://localhost/ConsumesAttribute_AmbiguousActions/CreateProduct");
// Act
var response = await Client.SendAsync(request);
var exception = response.GetServerException();
// Assert
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
Assert.Equal(typeof(AmbiguousActionException).FullName, exception.ExceptionType);
// Mono issue - https://github.com/aspnet/External/issues/19
Assert.Equal(
"Multiple actions matched. The following actions matched route data and had all constraints " +
"satisfied:" + PlatformNormalizer.GetNewLinesAsUnderscores(2) + "ActionConstraintsWebSite." +
"ConsumesAttribute_NoFallBackActionController." +
"CreateProduct" + PlatformNormalizer.GetNewLinesAsUnderscores(1) + "ActionConstraintsWebSite." +
"ConsumesAttribute_NoFallBackActionController.CreateProduct",
exception.ExceptionMessage);
}
[Fact]
public async Task NoRequestContentType_Selects_IfASingleActionWithConstraintIsPresent()
{
@ -131,7 +106,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
// Arrange
var input = "<Product xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns=\"http://schemas.datacontract.org/2004/07/ActionConstraintsWebSite\">" +
"xmlns=\"http://schemas.datacontract.org/2004/07/BasicWebSite.Models\">" +
"<SampleString>application/xml</SampleString></Product>";
var request = new HttpRequestMessage(
HttpMethod.Post,

View File

@ -13,9 +13,9 @@ using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class ContentNegotiationTest : IClassFixture<MvcTestFixture<ContentNegotiationWebSite.Startup>>
public class ContentNegotiationTest : IClassFixture<MvcTestFixture<BasicWebSite.Startup>>
{
public ContentNegotiationTest(MvcTestFixture<ContentNegotiationWebSite.Startup> fixture)
public ContentNegotiationTest(MvcTestFixture<BasicWebSite.Startup> fixture)
{
Client = fixture.Client;
}
@ -91,7 +91,9 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Arrange
var expectedContentType = MediaTypeHeaderValue.Parse("application/json;charset=utf-8");
var expectedOutput = "{\"Name\":\"John\",\"Address\":\"One Microsoft Way\"}";
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Home/UserInfo_ProducesWithTypeOnly");
var request = new HttpRequestMessage(
HttpMethod.Get,
"http://localhost/ContentNegotiation/UserInfo_ProducesWithTypeOnly");
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
// Act
@ -112,11 +114,11 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
// Arrange
var expectedContentType = MediaTypeHeaderValue.Parse("application/xml;charset=utf-8");
var expectedOutput = "<User xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\" " +
"xmlns=\"http://schemas.datacontract.org/2004/07/ContentNegotiationWebSite\">" +
"<Address>One Microsoft Way</Address><Name>John</Name></User>";
"xmlns=\"http://schemas.datacontract.org/2004/07/BasicWebSite.Models\">" +
"<Address>One Microsoft Way</Address><Name>John</Name></User>";
var request = new HttpRequestMessage(
HttpMethod.Get,
"http://localhost/Home/UserInfo_ProducesWithTypeAndContentType");
"http://localhost/ContentNegotiation/UserInfo_ProducesWithTypeAndContentType");
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
// Act
@ -271,7 +273,8 @@ END:VCARD
var expectedBody = "ProducesContentOnClassController";
// Act
var response = await Client.GetAsync("http://localhost/ProducesContentOnClass/ReturnClassNameContentTypeOnDerivedAction");
var response = await Client.GetAsync(
"http://localhost/ProducesContentOnClass/ReturnClassNameContentTypeOnDerivedAction");
// Assert
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
@ -287,7 +290,7 @@ END:VCARD
var expectedBody = "{\"MethodName\":\"Produces_WithNonObjectResult\"}";
// Act
var response = await Client.GetAsync("http://localhost/JsonResult/Produces_WithNonObjectResult");
var response = await Client.GetAsync("http://localhost/ProducesJson/Produces_WithNonObjectResult");
// Assert
Assert.Equal(expectedContentType, response.Content.Headers.ContentType);
@ -303,12 +306,12 @@ END:VCARD
// Arrange
var expectedContentType = MediaTypeHeaderValue.Parse("application/xml;charset=utf-8");
var expectedBody = @"<User xmlns:i=""http://www.w3.org/2001/XMLSchema-instance"" " +
@"xmlns=""http://schemas.datacontract.org/2004/07/ContentNegotiationWebSite""><Address>"
+ @"One Microsoft Way</Address><Name>John</Name></User>";
@"xmlns=""http://schemas.datacontract.org/2004/07/BasicWebSite.Models""><Address>" +
@"One Microsoft Way</Address><Name>John</Name></User>";
for (int i = 0; i < 5; i++)
{
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/Home/UserInfo");
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/ContentNegotiation/UserInfo");
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
request.Headers.AcceptCharset.Add(new StringWithQualityHeaderValue("utf-8"));

View File

@ -1,100 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.AspNet.Cors.Infrastructure;
using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class CorsMiddlewareTests : IClassFixture<MvcTestFixture<CorsMiddlewareWebSite.Startup>>
{
public CorsMiddlewareTests(MvcTestFixture<CorsMiddlewareWebSite.Startup> fixture)
{
Client = fixture.Client;
}
public HttpClient Client { get; }
[Theory]
[InlineData("GET")]
[InlineData("HEAD")]
[InlineData("POST")]
public async Task ResourceWithSimpleRequestPolicy_Allows_SimpleRequests(string method)
{
// Arrange
var origin = "http://example.com";
var request = new HttpRequestMessage(
new HttpMethod(method),
"http://localhost/CorsMiddleware/GetExclusiveContent");
request.Headers.Add(CorsConstants.Origin, origin);
// Act
var response = await Client.SendAsync(request);
// Assert
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("exclusive", content);
var responseHeaders = response.Headers;
var header = Assert.Single(response.Headers);
Assert.Equal(CorsConstants.AccessControlAllowOrigin, header.Key);
Assert.Equal(new[] { "http://example.com" }, header.Value.ToArray());
}
[Theory]
[InlineData("GET")]
[InlineData("HEAD")]
[InlineData("POST")]
[InlineData("PUT")]
public async Task PolicyFailed_Disallows_PreFlightRequest(string method)
{
// Arrange
var request = new HttpRequestMessage(
new HttpMethod(CorsConstants.PreflightHttpMethod),
"http://localhost/CorsMiddleware/GetExclusiveContent");
// Adding a custom header makes it a non-simple request.
request.Headers.Add(CorsConstants.Origin, "http://example.com");
request.Headers.Add(CorsConstants.AccessControlRequestMethod, method);
request.Headers.Add(CorsConstants.AccessControlRequestHeaders, "Custom");
// Act
var response = await Client.SendAsync(request);
// Assert
// Middleware applied the policy and since that did not pass, there were no access control headers.
Assert.Equal(HttpStatusCode.NoContent, response.StatusCode);
Assert.Empty(response.Headers);
// It should short circuit and hence no result.
var content = await response.Content.ReadAsStringAsync();
Assert.Equal(string.Empty, content);
}
[Fact]
public async Task PolicyFailed_Allows_ActualRequest_WithMissingResponseHeaders()
{
// Arrange
var request = new HttpRequestMessage(HttpMethod.Put, "http://localhost/CorsMiddleware/GetExclusiveContent");
// Adding a custom header makes it a non simple request.
request.Headers.Add(CorsConstants.Origin, "http://example2.com");
// Act
var response = await Client.SendAsync(request);
// Assert
// Middleware applied the policy and since that did not pass, there were no access control headers.
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Empty(response.Headers);
// It still has executed the action.
var content = await response.Content.ReadAsStringAsync();
Assert.Equal("exclusive", content);
}
}
}

View File

@ -9,9 +9,9 @@ using Xunit;
namespace Microsoft.AspNet.Mvc.FunctionalTests
{
public class OutputFormatterTest : IClassFixture<MvcTestFixture<ContentNegotiationWebSite.Startup>>
public class OutputFormatterTest : IClassFixture<MvcTestFixture<BasicWebSite.Startup>>
{
public OutputFormatterTest(MvcTestFixture<ContentNegotiationWebSite.Startup> fixture)
public OutputFormatterTest(MvcTestFixture<BasicWebSite.Startup> fixture)
{
Client = fixture.Client;
}

View File

@ -7,15 +7,10 @@
"warningsAsErrors": true
},
"dependencies": {
"ActionConstraintsWebSite": "1.0.0",
"AntiforgeryTokenWebSite": "1.0.0",
"ApiExplorerWebSite": "1.0.0",
"ApplicationModelWebSite": "1.0.0",
"BasicWebSite": "1.0.0",
"CompositeViewEngineWebSite": "1.0.0",
"ContentNegotiationWebSite": "1.0.0",
"ControllersFromServicesWebSite": "1.0.0",
"CorsMiddlewareWebSite": "1.0.0",
"CorsWebSite": "1.0.0",
"CustomRouteSample.Web": "1.0.0",
"EmbeddedViewSample.Web": "1.0.0",

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>af210f69-9d31-43af-ac3a-cd366e252218</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>41642</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,34 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.DependencyInjection;
namespace ActionConstraintsWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services
.AddMvc()
.AddXmlDataContractSerializerFormatters();
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
app.UseErrorReporter();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller}/{action}/{id?}");
});
}
}
}

View File

@ -1,19 +0,0 @@
{
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"webroot": "wwwroot"
}

View File

@ -1,4 +0,0 @@
ActionConstraintWebSite
===
This web site illustrates how to use action constraints to select the right action based on the request.

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>a353b17e-a940-4ce8-8bf9-179e24a9041f</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>49637</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,16 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
namespace AntiforgeryTokenWebSite
{
// This controller is reachable via traditional routing.
public class HomeController : Controller
{
public IActionResult Index()
{
return View("MyView");
}
}
}

View File

@ -1,30 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace AntiforgeryTokenWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
app.UseErrorReporter();
app.UseMvc(routes =>
{
routes.MapRoute("ActionAsMethod", "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
}

View File

@ -1,3 +0,0 @@
@{ Layout = "/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Home Page";
}

View File

@ -1,3 +0,0 @@
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>

View File

@ -1,18 +0,0 @@
{
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"webroot": "wwwroot"
}

View File

@ -1,5 +0,0 @@
AntiforgeryTokenWebSite
===
This web site illustrates how to use the antiforgery system to prevent CSRF attacks. The web site has an
`AccountsController` which uses an antiforgery token to validate incoming form posts.

View File

@ -1,9 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
namespace ActionConstraintsWebSite
namespace BasicWebSite.Controllers.ActionConstraints
{
[Route("ConsumesAttribute_AmbiguousActions/[action]")]
public class ConsumesAttribute_NoFallBackActionController : Controller

View File

@ -1,9 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
namespace ActionConstraintsWebSite
namespace BasicWebSite.Controllers.ActionConstraints
{
[Consumes("application/json")]
public class ConsumesAttribute_OverridesBaseController : Controller

View File

@ -1,9 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
namespace ActionConstraintsWebSite
namespace BasicWebSite.Controllers.ActionConstraints
{
[Consumes("application/xml")]
public class ConsumesAttribute_OverridesController : ConsumesAttribute_OverridesBaseController

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
namespace ActionConstraintsWebSite
namespace BasicWebSite.Controllers.ActionConstraints
{
[Route("ConsumesAttribute_PassThrough/[action]")]
public class ConsumesAttribute_PassThroughController : Controller

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
namespace ActionConstraintsWebSite
namespace BasicWebSite.Controllers.ActionConstraints
{
[Route("ConsumesAttribute_Company/[action]")]
public class ConsumesAttribute_WithFallbackActionController : Controller

View File

@ -1,19 +1,25 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Models;
using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc;
namespace AntiforgeryTokenWebSite
namespace BasicWebSite.Controllers
{
// This controller is reachable via traditional routing.
public class AccountController : Controller
public class AntiforgeryController : Controller
{
// GET: /Account/Login
public IActionResult Index()
{
return View();
}
// GET: /Antiforgery/Login
[AllowAnonymous]
public ActionResult Login(string returnUrl = null)
{
ViewBag.ReturnUrl = returnUrl;
ViewData["ReturnUrl"] = returnUrl;
return View();
}
@ -24,7 +30,7 @@ namespace AntiforgeryTokenWebSite
return "somestring";
}
// POST: /Account/Login
// POST: /Antiforgery/Login
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
@ -33,16 +39,16 @@ namespace AntiforgeryTokenWebSite
return "OK";
}
// GET: /Account/FlushAsyncLogin
// GET: /Antiforgery/FlushAsyncLogin
[AllowAnonymous]
public ActionResult FlushAsyncLogin(string returnUrl = null)
{
ViewBag.ReturnUrl = returnUrl;
ViewData["ReturnUrl"] = returnUrl;
return View();
}
// POST: /Account/FlushAsyncLogin
// POST: /Antiforgery/FlushAsyncLogin
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]

View File

@ -1,11 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class HomeController : Controller
public class ContentNegotiationController : Controller
{
public IActionResult Index()
{

View File

@ -1,12 +1,13 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Formatters;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.OptionsModel;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class FallbackOnTypeBasedMatchController : Controller
{
@ -64,7 +65,7 @@ namespace ContentNegotiationWebSite
}
public IActionResult ReturnString(
bool matchFormatterOnObjectType,
bool matchFormatterOnObjectType,
[FromServices] IOptions<MvcOptions> optionsAccessor)
{
var objectResult = new ObjectResult("Hello World!");

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Formatters;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
[Produces("application/FormatFilterController")]
public class FormatFilterController : Controller

View File

@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class NoContentController : Controller
{

View File

@ -6,7 +6,7 @@ using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Formatters;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class NoContentDoNotTreatNullValueAsNoContentController : Controller
{

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Formatters;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class NoProducesContentOnClassController : ProducesContentBaseController
{

View File

@ -1,12 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Formatters;
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Formatters;
using Newtonsoft.Json;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class NormalController : Controller
{

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Formatters;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
[Produces("application/custom_ProducesContentBaseController")]
public class ProducesContentBaseController : Controller

View File

@ -1,10 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using BasicWebSite.Formatters;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
[Produces("application/custom_ProducesContentOnClassController")]
public class ProducesContentOnClassController : ProducesContentBaseController

View File

@ -3,9 +3,9 @@
using Microsoft.AspNet.Mvc;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class JsonResultController : Controller
public class ProducesJsonController : Controller
{
[Produces("application/xml")]
public IActionResult Produces_WithNonObjectResult()

View File

@ -1,11 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using ContentNegotiationWebSite.Models;
using BasicWebSite.Formatters;
using BasicWebSite.Models;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class ProducesWithMediaTypeParametersController : Controller
{

View File

@ -4,7 +4,7 @@
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Controllers.ContentNegotiation
{
public class TextPlainController : Controller
{

View File

@ -7,7 +7,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Formatters
{
public class CustomFormatter : OutputFormatter
{

View File

@ -7,7 +7,7 @@ using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Formatters
{
public class PlainTextFormatter : OutputFormatter
{

View File

@ -5,12 +5,12 @@ using System;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ContentNegotiationWebSite.Models;
using BasicWebSite.Models;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Formatters
{
/// <summary>
/// Provides contact information of a person through VCard format.

View File

@ -5,12 +5,12 @@ using System;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using ContentNegotiationWebSite.Models;
using BasicWebSite.Models;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Net.Http.Headers;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Formatters
{
/// <summary>
/// Provides contact information of a person through VCard format.

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace ContentNegotiationWebSite.Models
namespace BasicWebSite.Models
{
public class Contact
{
@ -25,10 +25,4 @@ namespace ContentNegotiationWebSite.Models
public string Self { get; set; }
}
public enum GenderType
{
Male,
Female
}
}

View File

@ -0,0 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace BasicWebSite.Models
{
public enum GenderType
{
Male,
Female,
}
}

View File

@ -3,7 +3,7 @@
using System.ComponentModel.DataAnnotations;
namespace AntiforgeryTokenWebSite
namespace BasicWebSite.Models
{
public class LoginViewModel
{

View File

@ -3,7 +3,7 @@
using System.ComponentModel.DataAnnotations;
namespace ActionConstraintsWebSite
namespace BasicWebSite.Models
{
public class Product
{

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace ActionConstraintsWebSite
namespace BasicWebSite.Models
{
public class Product_Json : Product
{

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace ActionConstraintsWebSite
namespace BasicWebSite.Models
{
public class Product_Xml : Product
{

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace ActionConstraintsWebSite
namespace BasicWebSite.Models
{
public class Product_Text : Product
{

View File

@ -3,7 +3,7 @@
using System.ComponentModel.DataAnnotations;
namespace ContentNegotiationWebSite
namespace BasicWebSite.Models
{
[DisplayColumn("Name")]
public class User

View File

@ -14,10 +14,11 @@ namespace BasicWebSite
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.Conventions.Add(new ApplicationDescription("This is a basic website."));
});
services
.AddMvc(
options => { options.Conventions.Add(new ApplicationDescription("This is a basic website.")); })
.AddXmlDataContractSerializerFormatters();
services.AddLogging();
services.AddSingleton<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

View File

@ -1,17 +1,17 @@
@model AntiforgeryTokenWebSite.LoginViewModel
@model BasicWebSite.Models.LoginViewModel
@{
ViewBag.Title = "Log in";
Layout = "/Views/Shared/_FlushAsyncLayout.cshtml";
Layout = "_FlushAsyncLayout.cshtml";
ViewData["Title"] = "Log in";
}
@section Login
{
<h2>@ViewBag.Title.</h2>
<h2>@ViewData["Title"].</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@using (Html.BeginForm("FlushAsyncLogin", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
@using (Html.BeginForm("FlushAsyncLogin", "Antiforgery", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use a local account to log in.</h4>

View File

@ -0,0 +1,4 @@
@{
Layout = "_Layout.cshtml";
ViewData["Title"] = "Home Page";
}

View File

@ -1,14 +1,14 @@
@model AntiforgeryTokenWebSite.LoginViewModel
@model BasicWebSite.Models.LoginViewModel
@{
ViewBag.Title = "Log in";
ViewData["Title"] = "Log in";
}
<h2>@ViewBag.Title.</h2>
<h2>@ViewData["Title"].</h2>
<div class="row">
<div class="col-md-8">
<section id="loginForm">
@using (Html.BeginForm("Login", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
@using (Html.BeginForm("Login", "Antiforgery", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use a local account to log in.</h4>
@ -37,7 +37,7 @@
</section>
</div>
@using (Html.BeginForm("UseFacebookLogin", "Account", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
@using (Html.BeginForm("UseFacebookLogin", "Antiforgery", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<h4>Use Facebook login.</h4>

View File

@ -1,12 +1,12 @@
<html>
<head>
<title>@ViewBag.Title Antiforgery Functional Tests</title>
<title>@ViewData["Title"] Antiforgery Functional Tests</title>
</head>
@SetAntiforgeryCookieAndHeader()
@await FlushAsync()
<body>
@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })
@Html.ActionLink("Log in", "Login", "Antiforgery", routeValues: null, htmlAttributes: new { id = "loginLink" })
<div class="container body-content">
@RenderBody()
@await RenderSectionAsync("Login", required: false)

View File

@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title Antiforgery Functional Tests</title>
<title>@ViewData["Title"] Antiforgery Functional Tests</title>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
@ -14,7 +14,7 @@
@Html.ActionLink("ASP.NET Antiforgery tests", "Index", "Home", null, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
@await Html.PartialAsync("_LoginPartial")
@await Html.PartialAsync("_LoginPartial.cshtml")
</div>
</div>
</div>

View File

@ -0,0 +1,3 @@
<ul class="nav navbar-nav navbar-right">
<li>@Html.ActionLink("Log in", "Login", "Antiforgery", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
</ul>

View File

@ -3,14 +3,15 @@
"weblistener": "Microsoft.AspNet.Server.WebListener",
"web": "Microsoft.AspNet.Server.Kestrel"
},
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.Session": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.Session": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }

View File

@ -1 +0,0 @@
HelloWorld

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>a853b2ba-4449-4908-a416-5a3c027fc22b</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>8643</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,20 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
namespace CompositeViewEngineWebSite
{
public class HomeController : Controller
{
public ViewResult Index()
{
return View();
}
public ViewResult TestView()
{
return View("test-view");
}
}
}

View File

@ -1,31 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace CompositeViewEngineWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
// Add a view engine as the first one in the list.
services
.AddMvc()
.AddViewOptions(options =>
{
options.ViewEngines.Insert(0, new TestViewEngine());
});
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
// Add MVC to the request pipeline
app.UseMvcWithDefaultRoute();
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
namespace CompositeViewEngineWebSite
{
public class TestPartialView : IView
{
public string Path { get; set; }
public async Task RenderAsync(ViewContext context)
{
await context.Writer.WriteLineAsync("world");
}
}
}

View File

@ -1,19 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.AspNet.Mvc.ViewEngines;
namespace CompositeViewEngineWebSite
{
public class TestView : IView
{
public string Path { get; set; }
public async Task RenderAsync(ViewContext context)
{
await context.Writer.WriteLineAsync("Content from test view");
}
}
}

View File

@ -1,31 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ViewEngines;
namespace CompositeViewEngineWebSite
{
public class TestViewEngine : IViewEngine
{
public ViewEngineResult FindView(ActionContext context, string viewName, bool isMainPage)
{
if (string.Equals(viewName, "partial-test-view", StringComparison.Ordinal) ||
string.Equals(viewName, "test-view", StringComparison.Ordinal))
{
var view = isMainPage ? (IView)new TestView() : new TestPartialView();
return ViewEngineResult.Found(viewName, view);
}
return ViewEngineResult.NotFound(viewName, Enumerable.Empty<string>());
}
public ViewEngineResult GetView(string executingFilePath, string viewPath, bool isMainPage)
{
return ViewEngineResult.NotFound(viewPath, Enumerable.Empty<string>());
}
}
}

View File

@ -1 +0,0 @@
Hello @await Html.PartialAsync("partial-test-view")

View File

@ -1,18 +0,0 @@
{
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"webroot": "wwwroot"
}

View File

@ -1,4 +0,0 @@
CompositeViewEngineWebSite
===
This web site illustrates how to register and use custom `ViewEngines`.

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>c6e5affa-890a-448f-8de3-878b1d3c9fc7</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>49636</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,32 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.DependencyInjection;
namespace ContentNegotiationWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().AddXmlDataContractSerializerFormatters();
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
app.UseErrorReporter();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{
routes.MapRoute("ActionAsMethod", "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" });
});
}
}
}

View File

@ -1,19 +0,0 @@
{
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"webroot": "wwwroot"
}

View File

@ -1,5 +0,0 @@
ContentNegotiationWebSite
===
This web site illustrates in depth how MVC performs output content negotiation based on the input headers and
content. It also demonstrates various options available to participate in content negotiation process.

View File

@ -1,16 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
namespace CorsMiddlewareWebSite
{
[Route("CorsMiddleWare/[action]")]
public class BlogController : Controller
{
public string GetExclusiveContent()
{
return "exclusive";
}
}
}

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>b42d4844-fff8-4ec2-88d1-3ae95234d9eb</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>41642</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,24 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.Extensions.DependencyInjection;
namespace CorsMiddlewareWebSite
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
app.UseCors(policy => policy.WithOrigins("http://example.com"));
app.UseMvc();
}
}
}

View File

@ -1,20 +0,0 @@
{
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Cors": "6.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.Formatters.Xml": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
},
"webroot": "wwwroot"
}

View File

@ -1,4 +0,0 @@
CorsMiddlewareWebSite
===
This web site illustrates how to use CorsMiddleware to apply a policy for entire application.

View File

@ -1 +0,0 @@
HelloWorld

View File

@ -1,73 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features;
using Microsoft.Extensions.PlatformAbstractions;
namespace FilesWebSite
{
public class SendFileMiddleware
{
private const int DefaultBufferSize = 0x1000;
private readonly RequestDelegate _next;
public SendFileMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task Invoke(HttpContext context)
{
var environment = (IApplicationEnvironment)context.RequestServices.GetService(typeof(IApplicationEnvironment));
if (context.Features.Get<IHttpSendFileFeature>() == null)
{
var sendFile = new SendFileFallBack(context.Response.Body, environment.ApplicationBasePath);
context.Features.Set<IHttpSendFileFeature>(sendFile);
}
await _next(context);
}
private class SendFileFallBack : IHttpSendFileFeature
{
private readonly string _appBasePath;
private Stream _responseStream;
public SendFileFallBack(Stream responseStream, string appBasePath)
{
_responseStream = responseStream;
_appBasePath = appBasePath;
}
public async Task SendFileAsync(string path, long offset, long? length, CancellationToken cancellation)
{
using (var stream = new FileStream(Path.Combine(_appBasePath, path), FileMode.Open))
{
length = length ?? stream.Length - offset;
stream.Seek(offset, SeekOrigin.Begin);
var bufferSize = length < DefaultBufferSize ? length.Value : DefaultBufferSize;
var buffer = new byte[bufferSize];
var bytesRead = 0;
do
{
var bytesToRead = bufferSize < length ? bufferSize : length;
bytesRead = await stream.ReadAsync(buffer, 0, (int)bytesToRead);
length = length - bytesRead;
await _responseStream.WriteAsync(buffer, 0, bytesRead);
} while (bytesRead > 0 && length > 0);
}
}
}
}
}

View File

@ -18,8 +18,6 @@ namespace FilesWebSite
{
app.UseCultureReplacer();
app.UseMiddleware<SendFileMiddleware>();
app.UseMvc(routes =>
{
routes.MapRoute(name: null, template: "{controller}/{action}", defaults: null);