53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
namespace ChatRoomServer.Www.Controllers
|
|
{
|
|
using System.Data.Entity;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Web.Http.Cors;
|
|
using System.Web.Mvc.Filters;
|
|
using ChatRoomServer.Db;
|
|
using FSLib.MvcWeb;
|
|
using FSLib.Network.Http;
|
|
|
|
public class AnnouncementController : Controller
|
|
{
|
|
/// <summary>
|
|
/// Called when authorization occurs.
|
|
/// </summary>
|
|
/// <param name="filterContext">Information about the current request and action.</param>
|
|
protected override void OnAuthorization(AuthorizationContext filterContext)
|
|
{
|
|
base.OnAuthorization(filterContext);
|
|
|
|
var origin = filterContext.RequestContext.HttpContext.Request.Headers["Origin"];
|
|
if (!origin.IsNullOrEmpty())
|
|
{
|
|
if (!Regex.IsMatch(origin, @"^https?://.*?\.(fishlee\.net|liebao\.cn)$", RegexOptions.IgnoreCase))
|
|
{
|
|
filterContext.Result = new EmptyResult();
|
|
return;
|
|
}
|
|
|
|
filterContext.HttpContext.Response.AppendHeader("Access-Control-Allow-Origin", origin);
|
|
}
|
|
}
|
|
|
|
|
|
[AllowAnonymous]
|
|
[HttpGet, OutputCache(Duration = 1200, VaryByHeader = "Origin")]
|
|
public async Task<ContentResult> List()
|
|
{
|
|
var client = new HttpClient();
|
|
var ctx = client.Create<string>(HttpMethod.Get, $"http://{Request.Url.Host}:{Request.Url.Port}/api/announcement/list");
|
|
await ctx.SendAsync().ConfigureAwait(false);
|
|
|
|
return Content(ctx.Result, "application/json");
|
|
}
|
|
}
|
|
} |