Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myvas/aspnetcore.viewdivert
A Razor ViewLocationExpander to serve dedicated views for Weixin/Wechat, tablet, mobile or what-you-need customized user-agent browsers.
https://github.com/myvas/aspnetcore.viewdivert
aspnetcore mobile myvas razor razor-viewlocationexpander tablet viewdivert weixin
Last synced: about 3 hours ago
JSON representation
A Razor ViewLocationExpander to serve dedicated views for Weixin/Wechat, tablet, mobile or what-you-need customized user-agent browsers.
- Host: GitHub
- URL: https://github.com/myvas/aspnetcore.viewdivert
- Owner: myvas
- License: mit
- Created: 2017-03-26T03:41:17.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-02-02T12:44:57.000Z (1 day ago)
- Last Synced: 2025-02-02T13:35:50.355Z (1 day ago)
- Topics: aspnetcore, mobile, myvas, razor, razor-viewlocationexpander, tablet, viewdivert, weixin
- Language: C#
- Homepage:
- Size: 90.8 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# ViewDivert
[![GitHub (Pre-)Release Date](https://img.shields.io/github/release-date-pre/myvas/AspNetCore.ViewDivert?label=github)](https://github.com/myvas/AspNetCore.ViewDivert)
[![test](https://github.com/myvas/AspNetCore.ViewDivert/actions/workflows/dotnet.yml/badge.svg)](https://github.com/myvas/AspNetCore.ViewDivert)
[![deploy](https://github.com/myvas/AspNetCore.ViewDivert/actions/workflows/nuget.yml/badge.svg)](https://github.com/myvas/AspNetCore.ViewDivert)
[![NuGet](https://img.shields.io/nuget/v/Myvas.AspNetCore.ViewDivert.svg)](https://www.nuget.org/packages/Myvas.AspNetCore.ViewDivert)A Razor ViewLocationExpander to serve dedicated views for Weixin or what-you-need browsers.
## Usage
### ConfigureServices()
```csharp
services.AddViewDivert();
```### Use ViewDivert attribute
1. Put the attribute on Controller, so effect all actions in this Controller:
```csharp
///
/// YES, ViewDivert on all actions!
///
[ViewDivert]
public class HomeController : Controller
{
public IActionResult Index()
{
return View();
}public IActionResult About()
{
return View();
}
}
```2. Put only on the specified action(s):
```csharp
public class Home2Controller : Controller
{
///
/// YES, ViewDivert on me!
///
///
[ViewDivert]
public IActionResult Index()
{
return View();
}///
/// NO, ViewDivert NOT on me!
///
///
public IActionResult About()
{
return View();
}
}
``````
// Views/Xxx/Yyy.cshtml (default)
// Views/Xxx/Yyy.weixin.cshtml (MicroMessenger, via Weixin/Wechat browser)
// Views/Xxx/Yyy.tablet.cshtml (tablet, eg. iPad, iPad Pro and etc)
// Views/Xxx/Yyy.mobile.cshtml (mobile, via browser)
// Views/Xxx/Yyy.custom.cshtml (custom)
```### IDeviceResolver
```csharp
public class DeviceController : Controller
{
private readonly IDeviceResolver _deviceResolver;public DeviceController(IDeviceResolver deviceResolver)
{
_deviceResolver = deviceResolver;
}public IActionResult Index()
{
var deviceCode = _deviceResolver.Resolve(HttpContext);ViewData["DeviceCode"] = deviceCode;
return View();
}
}
```### Razor view
```csharp
@if (DeviceResolver.IsMicroMessenger(Context))
{
This browser is/as a Weixin.
}
```## Dev
* [Visual Studio 2022](https://visualstudio.microsoft.com)
* [.NET 8.0, 7.0, 6.0, 3.1](https://dotnet.microsoft.com/en-us/download/dotnet)