編集: 以下は、コントローラーを含むアセンブリへのパスと、コントローラー アクションを含むクラスの型名を示します。アーロン、これらを組み合わせれば、あなたが求めているものが得られるのではないでしょうか?
string assemblyPath = Assembly.GetExecutingAssembly().CodeBase;
string typeName = this.GetType().FullName;
たとえば、次のような結果が得られます
file:///C:/Projects/TestApp/TestApp.UI/bin/TestApp.UI.DLL
TestApp.UI.Controllers.TestController
「標準」の ASP.NET MVC の方法でコントローラーを配置して名前を付ける場合、上記の特定の組み合わせにより、C# ファイルへの正しいフル パスが得られる場合があります。
C:/Projects/TestApp/TestApp.UI/Controllers/TestController.cs
または相対パス:
Controllers/TestController.cs
以下は、コントローラーアクションへのルートを提供します。
1) string path = Request.Url.AbsolutePath
2) string appPath = Request.ApplicationPath;
string absPath = Request.Url.AbsolutePath;
string path = appPath.Length <= 1 ?
absPath : absPath.Replace(appPath, "");
TestController の Index アクション ( http://localhost:50027/Test/Index ) のリクエストの例: 上記は以下を返します。
1) /Test/Index
2) /Test/Index
ベース URL がhttp://localhost:50027/blogの Web サイトの場合、TestController の Index アクション ( http://localhost:50027/blog/Test/Index )のリクエストの例:
1) /blog/Test/Index
2) /Test/Index