0

I have a c# code and need to get full URL address from current page. In method I have :

string url = HttpContext.Current.Request.Url.AbsoluteUri;

but there is error. HttpContext does not exist in the current context

i have dll (using System.Web;) second try was:

string url = Request.Url.Host;

but error on Request does not exist.

how can get URL address ? my main question is. why i got error on HttpContext or Request.Url.Host ?

refreshg
  • 35
  • 1
  • 9
  • Read this. [get current page from url](http://stackoverflow.com/questions/4830763/get-current-page-from-url) – BilginAksoy Mar 27 '16 at 07:28
  • 1
    Possible duplicate of [How to get the current URL from ASP.NET code behind](http://stackoverflow.com/questions/17785885/how-to-get-the-current-url-from-asp-net-code-behind) – VVN Mar 27 '16 at 07:29
  • Do you see that he is saying HttpContext.Current=null? – Anik Saha Mar 27 '16 at 09:07
  • Do you show the code where do you want to do get it ? – Anik Saha Mar 27 '16 at 09:08
  • firstly i want to get URL string url = HttpContext.Current.Request.Url.AbsoluteUri; label.text = url; but i have error on HttpContext.Current. also wich class must have? using System.web have. – refreshg Mar 27 '16 at 09:09
  • @refreshg I think you are trying to get the URL in a class library or something and not in the code-behind file. You cannot access HttpContext or Request outside code-behind file. – Bharat Gupta Mar 27 '16 at 09:11
  • @Bharat Gupta i have a private void method. and in this method must get url. is it possible? – refreshg Mar 27 '16 at 09:14
  • Is the method inside the code-behind file? Is the method non-static? – Bharat Gupta Mar 27 '16 at 09:16
  • HttpContext.Current should do the trick. Please show us where you are calling this to identify why it is not working. You should call it on a thread that has http context and not some background thread that has none. – John Ephraim Tugado Mar 27 '16 at 09:18
  • @Bharat Gupta Here is full code >> https://docs.google.com/document/d/1PaieTxK3VUW2Vr5CFV1vbuuEb7I_iElblR76C_btFjc/edit?usp=sharing see getadress method – refreshg Mar 27 '16 at 09:23
  • What is this **Context** in EleWise.ELMA.Workflow.Scripts.ProcessScriptBase? I mean, what parameter are using in **Context** placeholder while creating the object of EleWise.ELMA.Workflow.Scripts.ProcessScriptBase? – Bharat Gupta Mar 27 '16 at 09:48
  • i use BMPN 2.0 leanguge and in this c#. Context in EleWise.ELMA.Workflow.Scripts.ProcessScriptBase this is for BPMN – refreshg Mar 27 '16 at 09:49
  • I am afraid, getadress will not work in this context. You can however pass the address from the code-behind (aspx.cs) while calling this getadress method. – Bharat Gupta Mar 27 '16 at 09:53
  • thanks. i will try – refreshg Mar 27 '16 at 10:03
  • @BharatGupta Yes, you can use HttpContext.Current in a class library or non-code behind context. The requirement is that you still must be in a web context - the code must be executing in response to a user request. – mason Mar 27 '16 at 15:09
  • Thanks for the information. Will try that out. – Bharat Gupta Mar 27 '16 at 15:49

0 Answers0