Example #1
0
    /// <summary>
    /// Invokes a request to the specified url and returns the result as an HTML string.
    /// </summary>
    /// <param name="thisHtml">The HTML helper instance that this method extends.</param>
    /// <param name="url">The url to invoke the request on.</param>
    /// <returns>The url contents as an HTML string.</returns>
    public static MvcHtmlString LoadUrl(this HtmlHelper thisHtml, string url)
    {
        //get the url as an absolute url
        UrlHelper helper = GetUrlHelper();

        url = helper.Absolute(url);
        var request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);

        //set the auth cookie so we don't just get the login page
        request.SetAuthenticationCookie();
        //get the response
        string responseString = request.GetResponseString();

        //return it as an html string
        return(new MvcHtmlString(responseString));
    }
 /// <summary>
 /// Gets the absolute URL (http://..../blah) to the specified URI
 /// </summary>
 /// <param name="urlHelper">The URL helper</param>
 /// <param name="uri">URI to link to</param>
 /// <returns>The absolute URL</returns>
 public static string ContentAbsolute(this UrlHelper urlHelper, string uri)
 {
     return(urlHelper.Absolute(urlHelper.Content(uri)));
 }
 public static Uri Absolute(this UrlHelper url)
 {
     return(url.Absolute(string.Empty));
 }
 /// <summary>
 /// Gets an absolute URL to the specified blog post
 /// </summary>
 /// <param name="urlHelper">The URL helper.</param>
 /// <param name="post">Blog post to link to</param>
 /// <returns>URL to this blog post</returns>
 public static string BlogPostAbsolute(this UrlHelper urlHelper, PostSummaryModel post)
 {
     return(urlHelper.Absolute(urlHelper.BlogPost(post)));
 }