Asp.NET/VB.NET:从URL/URI获取路径? [英] Asp.NET / VB.NET: Getting the path from the URL / URI?

查看:88
本文介绍了Asp.NET/VB.NET:从URL/URI获取路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有一个要部署在

www.foo.com/path1/default.aspx

www.foo.com/path1/default.aspx

www.foo.com/path2/default.aspx

www.foo.com/path2/default.aspx

知道我在文件夹"path1"还是"path2"中,最可靠的方法是什么?我可以直接抓住它,还是需要以某种方式在Request.Url.AbsolutePath上进行split()或...?

What would be the most reliable way to know if I was in the folder "path1", or "path2"? Can I grab that directly, or do I need to split() somehow on the Request.Url.AbsolutePath, or... ?

我只想根据用户所在的文件夹来更改颜色等.

I just want to change colors, etc. based on which folder the user is in.

感谢您的协助!

推荐答案

如果您想将该逻辑直接编码到页面中,是的,我会在Request.Url.AbsolutePath上使用split().

If you want to code that logic directly into the page, then yeah, I'd go with split() on Request.Url.AbsolutePath.

也就是说,我考虑将这种设置存储在web.config的AppSettings部分中.这样,如果您决定更改path2中的颜色,则只需编辑path2的web.config.如果您需要添加新路径,只需将其部署在此处并根据需要编辑web.config.

That said, I'd consider storing this kind of setting in the AppSettings section of web.config. That way if you decide to change the color in path2, you just need to edit the web.config for path2. If you need to add a new path, just deploy there and edit the web.config as appropriate.

这篇关于Asp.NET/VB.NET:从URL/URI获取路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆