ฉันกำลังอัปเกรดโครงการเป็น ASPNET5 แอปพลิเคชันของฉันคือ AngularJS Web App ที่ใช้การกำหนดเส้นทาง URL ของ HTML5 ( HTML5 History API )
ในแอปก่อนหน้าของฉัน ฉันใช้โมดูล URL Rewrite IIS ด้วยโค้ดเช่น:
<system.webServer>
<rewrite>
<rules>
<rule name="MainRule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="api/(.*)" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="signalr/(.*)" negate="true" />
</conditions>
<action type="Rewrite" url="Default.cshtml" />
</rule>
</rules>
</rewrite>
<system.webServer>
ฉันรู้ว่าฉันสามารถย้ายสิ่งนี้ได้ แต่ฉันต้องการลดการพึ่งพาหน้าต่างให้เหลือน้อยที่สุด จากการอ่านของฉัน ฉันคิดว่าฉันควรจะสามารถใช้ ASP.NET 5 Middleware เพื่อทำสิ่งนี้ให้สำเร็จ
ฉันคิดว่ารหัสจะมีลักษณะเช่นนี้ แต่ฉันคิดว่าฉันค่อนข้างไกล
app.UseFileServer(new FileServerOptions
{
EnableDefaultFiles = true,
EnableDirectoryBrowsing = true
});
app.Use(async (context, next) =>
{
if (context.Request.Path.HasValue && context.Request.Path.Value.Contains("api"))
{
await next();
}
else
{
var redirect = "http://" + context.Request.Host.Value;// + context.Request.Path.Value;
context.Response.Redirect(redirect);
}
});
โดยพื้นฐานแล้ว ฉันต้องการกำหนดเส้นทางอะไรก็ได้ที่มี /api
หรือ /signalr
ข้อเสนอแนะเกี่ยวกับวิธีที่ดีที่สุดในการทำสิ่งนี้ให้สำเร็จใน ASPNET5 หรือไม่
middleware
- person agua from mars   schedule 02.07.2015middleware
ตัวอย่างมากมายในGitHub
สิ่งหนึ่งที่ฉันเขียน: github.com/aguacongas/chatle/tree/dev/ src/ChatLe.HttpUtility - person agua from mars   schedule 02.07.2015