Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:46:53+00:00 2026-05-31T21:46:53+00:00

This probably is a dummy question but I cannot find a clear indication. I

  • 0

This probably is a dummy question but I cannot find a clear indication. I have a POCO class in a MVC3 web application whose only purpose is managing the backup of some files in the server. Typically it creates a backup and returns the filename to the controller, which sends an email with the URL for downloading it. This works fine, but I cannot build the absolute URL to be sent. No matter which function I use, I always get a relative URL, like /Backup/TheFile.zip, rather than e.g. http://www.somesite.com/Backup/TheFile.zip. I tried:

VirtualPathUtility.ToAbsolute("~/Backup/SomeFile.zip");
HttpRuntime.AppDomainAppVirtualPath + "/Backup/SomeFile.zip";
Url.Content("~/Backup/SomeFile.zip");

but they all return something like /Backup/SomeFile.zip. Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:46:54+00:00Added an answer on May 31, 2026 at 9:46 pm

    You can do it by the following:

    var urlBuilder =
        new System.UriBuilder(Request.Url.AbsoluteUri)
            {
                Path = Url.Action("Action", "Controller"),
                Query = null,
            };
    
    Uri uri = urlBuilder.Uri;
    string url = urlBuilder.ToString();
    // or urlBuilder.Uri.ToString()
    

    Instead of Url.Action() in this sample, you can also use Url.Content(), or any routing method, or really just pass a path.

    But if the URL does go to a Controller Action, there is a more compact way:

    var contactUsUriString =
        Url.Action("Contact-Us", "About",
                   routeValues: null /* specify if needed */,
                   protocol: Request.Url.Scheme /* This is the trick */);
    

    The trick here is that once you specify the protocol/scheme when calling any routing method, you get an absolute URL. I recommend this one when possible, but you also have the more generic way in the first example in case you need it.

    I have blogged about it in details here:
    http://gurustop.net/blog/2012/03/23/writing-absolute-urls-to-other-actions-in-asp-net-mvc/

    Extracted from Meligy’s AngularJS & Web Dev Goodies Newsletter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I fear this is probably a bit of a dummy question, but it has
This probably is a very very basic question but i can't seem to find
Probably a stupid question but so far I can't figure this out... I have
This probably sounds like a really dumb question, but here goes....Web Services, what the
This probably has a simple answer, but I must not have had enough coffee
This probably sounds really stupid but I have noo idea how to implement jquery's
Sorry for the probably dummy question but I'm lost. can Wi-fi network strength (dBm)
I know this probably is a fairly complicated question but... heres my case: I
I have a feeling that this probably is not possible using strictly CSS, but,
This is probably a dumb question, but in the introduction to TableViews, the author

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.