参考资料:https://sites.google.com/site/netcorenote/asp-net-core/get-scheme-url-host Example there's an given url: http://localhost:4800/account/login 获取整个url地址: 在页面(cstml)中 Microsoft.AspNetCore.Http.Extensions.UriHelper.GetDisplayUrl(Context.Request); 在
被测试Action 包含有Url对象的代码: data = new data { title = ds.Name, icon = "folder", attr = new { id = "root", href = Url.Action("ManageDSByLevel", new { levelid = firstlevel.ID }), name = ds.Name }, }, 在进行单元测试时需要Mock Url对象,以顺利通过测试,以下为
var url = new UrlHelper(filterContext.RequestContext); var url = new UrlHelper(HttpContext.Current.Request.RequestContext); url.Content(FormsAuthentication.LoginUrl) ; FormsAuthentication.LoginUrl='~/Login/Index' 发布程序在虚拟目录下,css 中图片引用要用相对路径,页面中的图片或者请求