0

I'm a bit confused about the ~ path in Asp.NET 6.x

Assume my Web site is hosted on IIS at: http://somesite.org/special/

I'm using Carter Lib but I don't think that should matter.

    public LogoutModule()
    {
        Get("/api/admin/logout", async ctx =>
        {
            await ctx
               .SignOutAsync("Cookies")
               .ConfigureAwait(false);

            ctx.Session.Clear();
            ctx.Response.Redirect("~/");
        });
    }

I thought the redirect would go to http://somesitename.org/special but instead it goes to:

http://somesitename.org/special/api/admin/~/

Redirecting using ctx.Response.Redirect("/"); doesn't work either. It then goes to:

http://somesitename.org/

In general I don't know the virtual directory this site is hosted in. I thought the ~ operator took care of that. What don't I understand here?

Mike Ward
  • 3,211
  • 1
  • 29
  • 42
  • Can you share what's in the `Location` header in the HTTP response on the client side? My assumption is the `~` is simply not being expanded and is being instead used verbatim. – Matthew Mar 11 '22 at 17:12
  • There's no `Location` header in `HttpContext.Request.Headers`. Should there be? – Mike Ward Mar 11 '22 at 18:21
  • If possible, you could try to know the virtual directory name and then try `/Special`. If that not possible and if you are hosting the site on the IIS then you could try using URL_Rewrite/Redirect may help to fix the issue. – Deepak-MSFT Mar 14 '22 at 03:25

0 Answers0