Check alle échte Black Friday-deals Ook zo moe van nepaanbiedingen? Wij laten alleen échte deals zien

[ASP.Net] Current path

Pagina: 1
Acties:

  • creator1988
  • Registratie: Januari 2007
  • Laatst online: 16:30
Ik vond hier al wat informatie maar het werkt gewoon niet in deze situatie:

http://www.thejackol.com/...pplication-path-c-aspnet/

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//omgezet naar VB

    Public Function getapppath() As String
        Dim apppath As String = ""

        With Request.Url
            apppath = .AbsoluteUri.Substring( _
            0, .AbsoluteUri.ToLower().IndexOf( _
            Request.ApplicationPath.ToLower(), _
            Request.Url.AbsoluteUri.ToLower().IndexOf( _
            .Authority.ToLower()) + _
            .Authority.Length) + _
            Request.ApplicationPath.Length)

            Return apppath
        End With
    End Function


retouneert 'http://localhost:72' i.p.v. 'http://localhost:7293/subdir'

Ik ben bezig met wat URL-rewriting, en ik wil nu de locatie van de applicatie (als URI) weten.

Dus als de bezoeker op
http://www.website.nl/deapplicatie/pagina/home/nogwat.aspx
of
http://www.website.nl/deapplicatie/default.aspx
staat

dan moet ik gewoon
http://www.website.nl/deapplicatie
terugkrijgen.

Het lijkt gewoon niet makkelijk mogelijk, als ik weet in welke subdirectory de pagina zich bevind kan het wel met
code:
1
Request.Url.AbsoluteUri.ToLower.Replace("admin/" & My.Computer.FileSystem.GetName(Request.PhysicalPath).ToLower, "").Split("?")(0)


in alle request.servervariables kan ik wel de naam van de pagina zien met het path, maar dan wordt de subdirectory van de applicatie ook meegenomen ('deapplicatie' bijvoorbeeld), dus die kan ik niet replacen, want dan werkt het niet als de app in een subdirectory draait.

:X

[ Voor 23% gewijzigd door creator1988 op 03-01-2008 10:52 ]


  • creator1988
  • Registratie: Januari 2007
  • Laatst online: 16:30
/* got it!

code:
1
Return Request.Url.GetLeftPart(UriPartial.Authority) & Request.ApplicationPath

  • Niemand_Anders
  • Registratie: Juli 2006
  • Laatst online: 09-07-2024

Niemand_Anders

Dat was ik niet..

C#:
1
2
3
4
5
        public static string GetHostname()
        {
            string vp = context.Request.ApplicationPath;
            return string.Format("{0}://{1}{2}", context.Request.Url.Scheme, context.Request.Url.Host, (vp.Length > 0) ? vp : "");
        }

Deze code werkt ook als je niet met een virtuele directory (productie bijvoorbeeld) werkt.


(context is eerder bepaald als protected static HttpContext context = HttpContext.Current;)

[ Voor 12% gewijzigd door Niemand_Anders op 03-01-2008 11:25 ]

If it isn't broken, fix it until it is..