我正在将我的项目升级到ASPNET5。我的应用程序是一个AngularJS Web应用程序,使用HTML5 Url路由(HTML5 History API)。
在我的以前的应用程序中,我使用了URL Rewrite IIS模块,代码如下:
我意识到我可以移植这个,但我想最小化我的Windows依赖。根据我的阅读,我认为我应该能够使用ASP.NET 5中间件来实现这一点。
我认为代码应该像这样,但我认为我离正确还很远。
基本上,我希望路由任何包含
在我的以前的应用程序中,我使用了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>
我意识到我可以移植这个,但我想最小化我的Windows依赖。根据我的阅读,我认为我应该能够使用ASP.NET 5中间件来实现这一点。
我认为代码应该像这样,但我认为我离正确还很远。
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中实现此目标的最佳方法的建议?
GitHub
上有很多middleware
示例。其中一个是我写的:https://github.com/aguacongas/chatle/tree/dev/src/ChatLe.HttpUtility - agua from mars