gpt4 book ai didi

c# - 如何获取完整的默认路由 url?

转载 作者:太空宇宙 更新时间:2023-11-03 10:26:59 28 4
gpt4 key购买 nike

<分区>

如何避免获取“/”(根路径),我想获取像 home/Index 这样的完整路径(作为我的默认路径)?

var redirectTo = htmlHelper.ViewContext.RequestContext.HttpContext.Request.Url.AbsolutePath; 
if (redirectTo.Equals("/"))
{
VirtualPathData vp = RouteTable.Routes.GetVirtualPath(htmlHelper.ViewContext.RequestContext, "Default", new RouteValueDictionary(new { controller = "Admin", action = "Index" }));
redirectTo = vp.VirtualPath;
}

    UrlHelper u = new UrlHelper(htmlHelper.ViewContext.RequestContext);;
redirectTo = u.RouteUrl("Default", ((Route)RouteTable.Routes["Default"]).Defaults);

但以上所有方法均无效。谢谢!

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com