Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

HttpServerUtility issue

Posted on 2004-08-03
4
Medium Priority
?
440 Views
Last Modified: 2008-01-09
Hello,

so I have webmatrix installed on my c:\ on my computer. I have a directory called employees, in which all my files are stored.
What I want to do is send an email to an account with a link to a .aspx file that contains an accountid for an employee.

Now when I just use the physical path on my harddrive i.e. c:\employees\confirm.aspx?id=asdfadsfdaa
The source code of the page opens and the page isn't served. I think this is becasue the file is not getting processed on IIS...

So I decided to use Server.MapPath...however I am writing this email send function in a custom class.

I am using the following string to acquire the path of my confirm.aspx file...

 string linkstring = HttpContext.Current.Server.MapPath("confirm.aspx?id=" + accountid);

This throws the following error:

System.ArgumentException: Illegal characters in path.

The accountid variable I am passing is simply a string of characters.....

what am I doing wrong? should I use Server.UrlPath instead if I am going to be using the website on http web?

thanks
0
Comment
Question by:simsingh
  • 2
4 Comments
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 800 total points
ID: 11711914
Hi there,
Server.MapPath(),  will give the physical address of that file. It will not give the URL for that file.
http://msdn.microsoft.com/library/en-us/iissdk/iis/ref_vbom_serommp.asp

I guess here you have to build the URL string, by yourself.

Dim linkstring = "http://www.YourWebSite.com/confirm.aspx?id=" + accountid

then send it through the mail.

** provided the "confirm.aspx" file must be inside the folder that Serverver.Mappath() indicates. I mean your Default website directory in IIS.

-Baan
0
 
LVL 15

Accepted Solution

by:
Thogek earned 1200 total points
ID: 11712108
Assuming that you're trying to resolve to a URL format....

Try
    string linkstring = HttpContext.Current.Server.MapPath("confirm.aspx") + "?id=" + accountid;

Or, better:
    string linkstring = HttpContext.Current.Server.MapPath("confirm.aspx") + "?id=" + HttpContext.Current.Server.UrlEncode(accountid);

More about the MapPath() method at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebhttpserverutilityclassmappathtopic.asp
0
 
LVL 15

Expert Comment

by:Thogek
ID: 11712123
Er... that should have said, "Assuming that you're trying to resolve to a local file path format..."

If you're trying to resolve to a linkable URL, Baan has the right idea above.  Or, something like
  string linkstring = "/confirm.aspx?id=" + accountid;
or
  string linkstring = "/confirm.aspx?id=" + HttpContext.Current.Server.UrlEncode(accountid);
might do just as well (assuming confirm.aspx is in the root directory of the IIS Web site in question -- otherwise, just modify the path above accordingly).
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11712137
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

782 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question