Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the url from the business logic layer?

Tags:

c#

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 ?

like image 732
Liran Friedman Avatar asked Sep 27 '22 22:09

Liran Friedman


1 Answers

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.

like image 55
Vikas Rana Avatar answered Oct 05 '22 08:10

Vikas Rana