Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

HttpServerUtility issue

Posted on 2004-08-03
4
Medium Priority
?
439 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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