Get original url without non-standard port (C#)

前端 未结 6 881
执念已碎
执念已碎 2021-02-12 21:43

First question!


Environment

MVC, C#, AppHarbor.

Problem

I am calling an openid provider,

6条回答
  •  说谎
    说谎 (楼主)
    2021-02-12 22:13

    I recently ran into an issue where I compared a URL to the current URL, and then highlighted navigation based on that. It worked locally, but not in production.

    I had http://example.com/path/to/file.aspx as my file, but when viewing that file and running Request.Url.ToString() it produced https://example.com:81/path/to/file.aspx in a load balanced production environment.

    Now I am using Request.Url.AbsolutePath to just give me /path/to/file.aspx, thus ignoring the schema, hostname, and port numbers.

    When I need to compare it to the URL on each navigation item I used: New Uri(theLink.Href).AbsolutePath

提交回复
热议问题