M
M
MADm2016-03-31 11:55:37
ASP.NET
MADm, 2016-03-31 11:55:37

How to get the absolute url of an ASP.NET MVC application?

How to get the absolute url of the application, taking into account ports and protocol, without using Request? Those if I test on local should get localhost: 55039 if I hosted the application then https://toster.ru/

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2016-03-31
@dmitryKovalskiy

There is only HttpContext.Current in Application_Start. It's just not clear what you want. If you have some environment settings that depend on the mode of operation (under debugging or combat), then there are simpler solutions for this - Web.Debug.config , Web.Release.config

A
atticus_finch, 2016-04-01
@atticus_finch

Alternatively, you can use Application_BeginRequest instead of Application_Start()

protected void Application_BeginRequest(object sender, EventArgs e)
        {
            var current = HttpContext.Current.Request.Url.AbsoluteUri;
        }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question