An open API service indexing awesome lists of open source software.

https://github.com/alexinea/dotnet-url-rewrite-examples

URL Rewrite Samples
https://github.com/alexinea/dotnet-url-rewrite-examples

rewrite

Last synced: about 1 month ago
JSON representation

URL Rewrite Samples

Awesome Lists containing this project

README

          

# ASP.NET UrlWrite 样例

### 问题

现有 `pc` 和 `mobile` 两文件夹(其文件夹内的结构也不同),根据用户的设备类型自动选择显示 pc 版或 mobile 版。

> **推荐**:使用栅格化的自适应设计让页面自动适应不同设备,以避免本模块造成的性能损失。

***

### ASP.NET URL Rewrite

项目:`src\UrlWrite.AspNet`

**仅可用于 IIS 7+**

`web.config` 的改动:

在 `system.webServer:modules` 内增加配置:

```

```

在 `system.webServer:handlers` 内增加配置:

```

```

推荐阅读:

+ [Bikeman868/UrlRewrite.Net](https://github.com/Bikeman868/UrlRewrite.Net)

***

### ASP.NET Core URL Rewrite

项目:`src\UrlRewrite.AspNetCore`

NuGet 安装:

```
PM> install-package Wangkanai.Responsive -pre
```

在 `ConfigureServices` 方法中配置:
```
services.AddResponsive()
.AddViewSuffix()
.AddViewSubfolder();
```

在 `Configure` 方法中使用中间件:
```
app.UseResponsive();
```

`ASP.NET Core Responsive` 会根据你设备的种类调用不同的视图:

+ 如果使用的是 `AddViewSuffix()`,则路径形如 `views/[controller]/[action]/index.mobile.cshtml`
+ 如果使用的是 `AddViewSubfolder()`,则路径形如 `views/[controller]/[action]/mobile/index.cshtml`

推荐阅读:

+ [URL Rewriting Middleware in ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/url-rewriting)
+ [ASP.NET Core Responsive](https://github.com/wangkanai/Responsive)