Solved

HttpServerUtility issue

Posted on 2004-08-03
4
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 18

Assisted Solution

by:DotNetLover_Baan
DotNetLover_Baan earned 200 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 300 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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