How can I get the url at the business logic level?

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 the website is running on.

For example, this url: http: // localhost: 56240 / Management / Quiz.aspx? QuizID = 46

I need a way to get this part: http: // localhost: 56240 using C # code from the business logic layer (means I cannot use the Request object or context.Request).

Is there a way to do this?

+3


source to share


2 answers


In your class, you can use the HttpContext.Current property (in System.Web.dll). From there, you can also use the Request object. 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.

+1


source


call the method from the presentation layer and pass it HttpContext

to the business logic layer you can use HttpContext.Request.Url.Authority

to get your domainhttp://localhost:56240



or you can pass Request.Url.Authority

as a string to your method if you need another thing inHttpContext

0


source







All Articles