I have a business logic layer in a C# project and I need to find a way to generate a url based on the base url that is running the web site.
For example, this is the url: http://localhost:56240/Management/Quiz.aspx?QuizID=46
I need a way to get this part: http://localhost:56240 using a C# code from the business logic layer (means I don't can't use the Request object or context.Request).
Is there a way to do that ?
From your class, you can use the HttpContext.Current property (in System.Web.dll). From there, you can use Request object as well. For example
HttpRequest request = HttpContext.Current.Request;
string url = request.Url.Authority.ToString();
Don't forget to include the reference for System.Web in your class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With