How can I get complete and base type of URL in C# asp.net MVC web-application, controller, for example, if my web-application URL is https://qawithexperts.com/questions/111/invalid-uri-the-format-of-the-uri-could-not-be-determined-er
https://qawithexperts.com //base url https://qawithexperts.com/questions/111/invalid-uri-the-format-of-the-uri-could-not-be-determined-er // complete url /questions/111/invalid-uri-the-format-of-the-uri-could-not-be-determined-er // after base part of it
how can I get all types of URL in C#?
I would like to save "after base part" of URL in database for some purpose, thanks
You can get the base Url(https://qawithexperts.com) in C# using the code below
//Get request from Current HttpContext var request = HttpContext.Current.Request; //request.Url.Scheme gives output as https/http //while request.Url.Authority give us Domain name var baseUrl= request.Url.Scheme+"://"+ request.Url.Authority;
Continuing the above code, you can get absolute URL(or you can say after base URL, ie. like /questions/111/invalid-uri-the-format-of-the-uri-could-not-be-determined-er ) using the code below
request.Path; //gives you absolute URL //or request.Url.AbsolutePath; // also does the same thing to provide you '/questions/112/how-to-get-complete-url-and-base-url-in-mvc'
Using the above C# asp.net code you can save these URL (absolute & web-base url) in database or do something else with them.