我可以在没有严格编码(硬编码)的情况下获得asp.net上的当前屏幕名称吗



有没有办法在不进行硬编码的情况下获得asp.net的当前屏幕名称?

string ScreenName = HttpContext.Current.Request.Url.AbsoluteUri;

我试过了,得到了完整的网址。

如果您想从url中获取域名,请使用以下代码:

string[] hostParts = new System.Uri(sURL).Host.Split('.');
string domain = String.Join(".", hostParts.Skip(Math.Max(0, hostParts.Length - 2)).Take(2));

或:

var host = new System.Uri(sURL).Host;
var domain = host.Substring(host.LastIndexOf('.', host.LastIndexOf('.') - 1) + 1);

其中";sURL";是您的URL。

我找到了一个代码。对我来说,string path是很好的

string url = HttpContext.Current.Request.Url.AbsoluteUri;
// http://localhost:1302/TESTERS/Default6.aspx
string path = HttpContext.Current.Request.Url.AbsolutePath;
// /TESTERS/Default6.aspx
string host = HttpContext.Current.Request.Url.Host;
// localhost

最新更新