System.Net.HttpWebRequest.Create(url) Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RamonPV
    New Member
    • Apr 2009
    • 5

    System.Net.HttpWebRequest.Create(url) Problem

    Hello:

    I am trying to send an email which body will be a local aspx page, but when I try to get the page html using System.Net.Http WebRequest.Crea te(url) I am getting this error:

    Invalid URI: The format of the URI could not be determined

    I read that I need to provide the full URI but I do not know how to do that so that it works when debuging(here I get a path like this http://localhost:43898/MyAppName/...) my application and also on the real server where the application is hosted(here I get a path like this: http://www.myDomain.com/...).

    I am using ResolveUrl("~/Member/AppSubmitNotifi cation.aspx") but i do not know how to provide the full path to avoid this error.
  • markwiseman
    New Member
    • Apr 2009
    • 1

    #2
    This is how i get my application root URL
    Code:
    public static string RootUrl()
        {
            return HttpContext.Current.Request.Url.AbsoluteUri.Substring(0, 
                      HttpContext.Current.Request.Url.AbsoluteUri.IndexOf(HttpContext.Current.Request.Url.AbsolutePath) + 1);
        }
    
    public static string ApplicationRootUrl()
        {
            string root = RootUrl();
    
            if (root.Substring(root.Length - 1, 1) == "/" )
                root = root.Substring(0, root.Length - 1);
    
            root += HttpContext.Current.Request.ApplicationPath;
    
            if(root.Substring(root.Length - 1, 1) == "/" )
                root = root.Substring(0, root.Length - 1);
    
            return root;
        }

    Comment

    Working...