Autor Beitrag
rittergig
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Di 26.07.11 15:39 
Hallo ich brauche den absoluten Pfad meiner Anwendung. Also die URL, ohne Parameter, Methode und Controllername

Beispiel für folgende URLs:

www.xyz123.de/
www.xyz123.de/Test
www.xyz123.de/Test/DoTest
www.xyz123.de/Test/DoTest/1
www.xyz123.de/Test/DoTest/1?par1=x
www.xyz123.de/Test/DoTest?id=1?par1=x

möchte ich immer
www.xyz123.de/
erhalten.

Wie kann ich den ermitteln?

Gruße, Peter
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 26.07.11 15:49 
Zum Beispiel über die Uri Klasse.
rittergig Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 33



BeitragVerfasst: Mi 27.07.11 11:37 
Danke.
Ich habe es für das <base>-Tag gebraucht, weil einige ASP.NET Usercontrols, welche Bilder generiert haben, nicht funktioniert haben.
Grund war der, dass der Pfad zu den Bildern relativ angegeben war, aber dieser durch die veränderte URL bei MVC nicht mehr stimmten.

Das habe ich nun in der _Layout.cshtml eingefügt
ausblenden C#-Quelltext
1:
<base href="@MyNameSpace.MvcApplication.GetBasicPath(this.Request)" />					

GetBasicPath:
ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
        public static string GetBasicPath(HttpRequestBase request)
        {
            string url = request.Url.AbsoluteUri;
            string x = request.RawUrl;

            return url.Remove(url.IndexOf(x));
        }