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

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

First question!


Environment

MVC, C#, AppHarbor.

Problem

I am calling an openid provider,

6条回答
  •  渐次进展
    2021-02-12 22:04

    If you use the UrlBuilder class in the framework you can easly get around this. On the builder class if you set the port to -1 then the port number will be removed:

    new UriBuilder("http://sub.example.com:15232/callback"){ Port = -1}
    

    returns : http://sub.example.com/callback

    To keep the port number on a local machine just check Request.IsLocal and don't apply -1 to the port.

    I would wrap this into a extension method to keep it clean.

提交回复
热议问题