• ActionFilterAttribute做切面编程的Url的格式化例子


    /// <summary>
    /// 格式化Url过滤器
    /// </summary>
    public class UrlFormatFilter : System.Web.Mvc.ActionFilterAttribute
    {
    /// <summary>
    /// 在Action执行前执行
    /// </summary>
    /// <param name="filterContext"></param>
    public override void OnActionExecuting(System.Web.Mvc.ActionExecutingContext filterContext)
    {
    string url = filterContext.HttpContext.Request.Url.OriginalString;
    if (System.Text.RegularExpressions.Regex.IsMatch(url, "[A-Z]"))
    {
    url = url.ToLower();
    filterContext.HttpContext.Response.StatusCode = 301;
    filterContext.HttpContext.Response.Redirect(url, true); 
    }
    }
    }
    

    /// <summary>
    /// SEO始发城市Action
    /// </summary>
    /// <param name="code"></param>
    /// <returns></returns>
    [UrlFormatFilter]
    [NoCacheFilter]
    public ActionResult TejiaCity(string city)
    {
    city = city ?? string.Empty;
    IBaseInfoSearch baseInfoService = ServiceFactory.BaseInfoSearch();
    AirCityInfo cityInfo = baseInfoService.GetAirCityByName(city);
    CityLowPriceViewModelBuilder builder = new CityLowPriceViewModelBuilder(cityInfo);
    CityLowPriceViewModel model = builder.Build(this.ControllerContext);

    // 初始化页面头
    InitTejiaCityPageInfo(cityInfo);
    InitlizeRegisterResource();
    return View("TejiaCity", model);
    }

      

      

  • 相关阅读:
    《构建之法》阅读笔记4
    团队冲刺第七天
    团队冲刺第六天
    团队冲刺第五天
    团队冲刺第四天
    团队冲刺第三天
    构建之法阅读笔记03
    第十四周进度条
    第二阶段冲刺站立会议10
    第二阶段冲刺站立会议09
  • 原文地址:https://www.cnblogs.com/adam/p/2347087.html
Copyright © 2020-2023  润新知