How do I get the correct path in asp.net when deploying from localhost to development server?

I have a simple web application that contains a folder called documents in the root of the website. Inside the documents there is a file called test.doc. The path and file are stored in the database, and when the web application starts, it reads the values ​​and creates the correct link to test.doc, in this case it is http: //localhost/documents/test.doc . The problem occurs when publishing to a folder on the development server. When I do this, my url is broken because it becomes something like this, http: //development/testapp/documents/test.doc . It fails because it looks for test.doc at http: //development/documents/test.doc . I am not sure how to solve this problem.

I'm currently doing this in markup, but I'm not sure how to use ResolveUrl or ResolveClientUrl with it:

<a runat="server" href='<%# Eval("url") %>'><%#Eval("title") %></a>

      

+2


source to share


5 answers


Try to use the function ResolveUrl

for the correct map.



ResolveUrl("~/documents/test.doc");

      

+1


source


You can use ResolveClientUrl method to map URLs correctly. Grab the url from the database, add "~ /" and go to ResolveClientUrl.



0


source


I am using a variable to store the root path. For production it's just "/". For my dev machine, this is "/ testapp /" (or whatever). I read this from the entry under "appsettings" in my web.config file. I am using a variable to create page paths etc., for example:

string docPath = WebRootPath + "documents/test.doc"

      

0


source


Another answer is to use IIS instead of Personal Web Server (PWS-ie, built-in VS.NET-built-in web server). Testing and debugging is much faster using IIS, and it really doesn't take long once you're used to it. It also addresses many of these problems that arise from the different routing scheme in the PWS.

Download the IIS administration tool to create multiple websites with IIS 5.1 (XP).

0


source


Markup:

<a runat="server" href='<%# CustomResolveURL(Eval("url")) %>'><%#Eval("title") %></a>

      

Codebehind:

protected string CustomResolveURL(object obj)
{
    string result = string.empty;
    string url = (string)obj;
    if(!string.IsNullOrEmpty(url))
    {
        result = ResolveUrl("~/" + url);
    }
    return result;
}

      

0


source







All Articles