Render a hyperlink in a email template - asp.net

I am trying to render a hyperlink in an email template which will be sent to the user and if the user clicks on that link it will direct to a unique url. I have given the coding below,
email.AddMailmerge("RequestUrl", "Feedback Requests")
My problem is the link doesnt resolve correctly and take me to the right url. What am I doing wrong?
It resolves as:
C:\Users\Test\Desktop\localhost/Requests/Requests.aspx?Company_ID=KirprZ17bg5u5Qf1

Make sure you Appsetting contains http:// so instead of just
localhost
it needs to be
http://localhost

Be sure to format your href with quotes. Instead of relying on your app.config's value, which is return the C:\ value, use the .NET methods to get the current domain/URL.
Dim target As String = _
String.Format("<a href='{0}/Requests/Requests.aspx?Company_ID={1}'>Feedback Requests</a>",_
Request.Url.GetLeftPart(UriPartial.Authority),_
objCompany.IDHashed)

Dim strRequestLink As String = System.Configuration.ConfigurationManager.AppSettings("DomainName") & "/Requests/Requests.aspx?Company_ID=" & Me.ID & "&key=" & Me.IDHashed
Dim strRequestUrl As String = "http://" & strRequestLink & ""
I used the above formatting.

Related

get current url of the page (used URL Rewrite)

I am working on classic asp application.
I have use URL rewrite on some pages.
How can i get current url of the page in classic asp?
Example:
http://www.site.com/page.asp ---> url rewrite in IIS ---> http://www.site.com/home/page
so here i want current url of the page which is http://www.site.com/home/page
Please help me.
Thanks.
There's no fancy one function that does it all.
First you need to get the protocol (if it is not always http):
Dim protocol
Dim domainName
Dim fileName
Dim queryString
Dim url
protocol = "http"
If lcase(request.ServerVariables("HTTPS"))<> "off" Then
protocol = "https"
End If
Now the rest with optional query string:
domainName= Request.ServerVariables("SERVER_NAME")
fileName= Request.ServerVariables("SCRIPT_NAME")
queryString= Request.ServerVariables("QUERY_STRING")
url = protocol & "://" & domainName & fileName
If Len(queryString)<>0 Then
url = url & "?" & queryString
End If
Hope it works for you.
You can try to output all ServerVariables like so:
for each key in Request.Servervariables
Response.Write key & " = " & Request.Servervariables(key) & "<br>"
next
Maybe the URL you seek is already there. We use the Rewrite module and there is a ServerVariable called HTTP_X_ORIGINAL_URL that contains the rewritten URL path, e.g. "/home/page" in your example.
Protocol (HTTPS=ON/OFF) and Server (SERVER_NAME) can also be found in the ServerVariables.
If you use URL Rewrite, the url data can only be retrieved in this way:
Request.ServerVariables("HTTP_X_ORIGINAL_URL")
Example
Dim domainName, urlParam
domainName = Request.ServerVariables("SERVER_NAME")
urlParam = Request.ServerVariables("HTTP_X_ORIGINAL_URL")
response.write(domainName & urlParam)

how to get the remote url

I am using
Dim url As String = Server.MapPath("MyFiles") & "\" &
System.IO.Path.GetFileName(hpf.FileName)
to get the url of the uploaded file.
The result i get is
D:\2008VS\LTC INDIA\LTCIndia v 1.52\AdminPanel\MyFiles\1.jpg
i want it to be like this http://www.abcd.com/AdminPanel/MyFiles/1.jpg
Kindly let me know if posting the whole code would be of any help.
You could use the ResolveUrl method:
Dim url As String = ResolveUrl("~/MyFiles/" & System.IO.Path.GetFileName(hpf.FileName))

Show if page URL matches string in classic ASP?

I'm trying to create an if statement which shows a line of JavaScript only if the current page URL matches a given string. Here's some pseudo code:
if URL matches ("example.com/sitename/") then
response.Write("<script='file.js'></script>")
end if
The problem is how do I check whether the URL of the current page matches the string?
Many thanks!
Thanks for your responses. I'm trying to make it a little more complicated with an array of possible URL matches. I've created the following asp, but it doesn't work properly. The script is being written on a page where the URL doesn't match. Is there anything that looks wrong? I can't figure it out!
<%
Dim pageURL
pageURL = Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")
URLArray = Array("example.net/folder1/","example.net/folder2/")
For Each URLsnippet In URLArray
if instr(pageURL, URLsnippet) then
response.Write("<!--BEGIN EXCLUDE--><script type='text/javascript' src='script.js'></script><!--END EXCLUDE-->")
else
end if
Next
%>
It should match URLs matching example.net/folder1 and example.net/folder2, but it's also matching example.net folder3!
try
if Request.ServerVariables("URL") = "/myurl.com/script.asp" then
' do stuff
end if
If you just want the url try this
var url = "<%=Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")";
if(url == "site.com/script.asp")
{
//Do stuff
}
If you also need the querystring try
var url = "<%=Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL") & "?" & Request.Querystring%>";
if(url == "site.com/script.asp?var=123")
{
//Do stuff
}

How to Make Very Simple ASP.Net Password Protected Page

I am looking for a very simple solution to password protect an ASP.Net page.
I found exactly what I am looking for here but it is in ASP and I do not know the syntax to convert it to ASP.Net.
It simply creates a temporary cookie that will expire as soon as they close their browser window.
I am not looking to store the username / password in a db. I will manually change the password occasionally.
Simply helping me convert the following code to ASP.Net would be wonderful!
This goes on the logon.aspx page and pulls values from a form.
Username="Administrator"
Password="Admin"
Validated = "OK"
if Strcomp(Request.Form("User"),Username,1)=0 AND Request.Form("password") = Password then
Response.Cookies("ValidUser") = Validated
If (Request.QueryString("from")<>"") then
Response.Redirect Request.QueryString("from")
else
Response.Redirect "MyPage.aspx"
End if
Else
If Request.Form("User") <> "" then
Response.Write "<h3>Authorization Failed.</h3>" & "<br>" & _ "Please try again.<br> <br>"
End if
End if
This goes on the password protected page to confirm the cookie was created.
Validated = "OK"
if Request.Cookies("ValidUser") <> Validated then
dim s
s = "http://"
s = s & Request.ServerVariables("HTTP_HOST")
s = s & Request.ServerVariables("URL")
if Request.QueryString.Count > 0 THEN
s = s & "?" & Request.QueryString
end if
Response.Redirect "Logon.aspx"
End if
Just use the built-in forms authentication and setup your credentials store in the web.config.
Here's a quick and dirty example
Another example

sHow to determine the path of the current web site

I wanted to create a function which would return the path of the current web site. This is what I thought was working while running in the IDE:
Public Shared Function WebsiteAbsoluteBaseUrl() As String
Dim RequestObject As System.Web.HttpRequest = HttpContext.Current.Request
Return "http://" & RequestObject.Url.Host & ":" & _
RequestObject.Url.Port & "/" & _
RequestObject.Url.Segments(1)
End Function
this seem like it should work? Is there a more straight forward way?
I am trying to replace all occurrences of the tag "{WebSiteBaseUrl} in an html email with the absolute web site path.
<A HREF="{WebSiteBaseUrl}Files/filename.pdf/>Some Text</A>
I don't want to have to parse the template and try to make sense of it in order to use MapPath function on a relative path to a file name.
The resulting email will become the html body of an html email, so I need the links to be absolute.
Some Text
I guess what I am seeing in dev, running in the IDE, is that "RequestObject.Url.Segments(1)" returns the name of the virtual folder and that in production it seems to be returning the name of the web page. I guess this probably has to do with how the web site is set up in IIS.
What does this suggest about how the web site is set up in production and how would you suggest I modify the code to yield a correct path after replacing {WebSiteBaseUrl} with the result of the function? This assumes that the file "filename.pdf" is in the relativepath ~/files/filesname.pdf.
You can use Request.Url.AbsoluteUri for this. Server.MapPath(".") will give you physical path.
Also you can use other Request properties which are listed here.
Try this to get the website's application path:
Public shared ReadOnly Property FullyQualifiedApplicationPath() As String
Get
Dim appPath As String = Nothing
Dim context As HttpContext = HttpContext.Current
If Not context Is Nothing Then
'Formatting the fully qualified website url/name
appPath = String.Format("{0}://{1}{2}{3}", _
context.Request.Url.Scheme, _
context.Request.Url.Host, _
IIf(context.Request.Url.Port = 80, String.Empty, ":" & context.Request.Url.Port), _
context.Request.ApplicationPath)
End If
Return appPath
End Get
End Property
or try this (just founded):
HttpContext.Current.Request.UrlInternal

Resources