Simple URL routes in WCF Rest 4.0 without trailing slash

后端 未结 7 1436
太阳男子
太阳男子 2021-02-01 20:27

I have a WCF REST 4.0 project based on the the WCF REST Service Template 40(CS). I\'d like to expose simple service endpoint URLs without trailing slashes. For example:

7条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 21:05

    Try putting this in the Global.asax.cs

        protected void Application_BeginRequest(object sender, EventArgs e)
        {
            string rawUrl = HttpContext.Current.Request.RawUrl.ToLower();
    
            if (rawUrl.EndsWith("/cars"))
            {
                HttpContext.Current.RewritePath(rawUrl + "/");  // append trailing slash
            }
        }
    

提交回复
热议问题