Link to a different page in asp.net - asp.net

I have the following code which should go to a particular company page from the request page. In the website folder Company page is under a folder called Companies and the request page is under Requests folder.
Dim strUrl As String = "/Companies/Details.aspx?Company_ID=" & .Company_id
litlCompany.Text = "" & .Company.Name & ""
The Url should be built as,
http://localhost/Companies/Details.aspx?Company_ID=222
But it comes as,
http://localhost/Requests/Companies/Details.aspx?Company_ID=222
Does anyone knows why?

I'm assuming you are currently on http://localhost/Requests/something.aspx? If so, that's because you forgot the tilde root specifier:
~/Companies/Details.aspx
Which should fix your problem.

You can also try
Page.ResolveClientUrl("~/Companies/Details.aspx?Company_ID=" + Company_id)

By the name of your control it appears that you are using a Literal.
Try changing this to a HyperLink, then you won't need to put the HTML (<a href=...) in the text property, you will be able to use hypCompany.NavigateUrl = strUrl and ASP.Net will generate it for you. This is the neatest way to do it anyhow.
Also add in the tilde to go to the root :-)
E.G.
Dim strUrl As String = "~/Companies/Details.aspx?Company_ID=" & .Company_id
hypCompany.NavigateUrl = strUrl

Am assuming that this link is built in the request.aspx page.
I think the a href is being rendered to the current httpcontext. Have you tried creating the string as :
Dim strUrl As String = "~/Companies/Details.aspx?Company_ID=" & .Company_id
I think this will work if the Companies folder is in the root. The tilda should ensure it looks from the root down.

Related

What is this redirection called and how can it be setup for an ASP based site?

Does this redirection method have a specific name, and how do I set it up for an ASP based site?
http://www.example.com/?URL=www.redirecteddomain.com
Ok, in that case, it not really the web server, but simply your code that can do this.
so, if you web page was:
http://localhost/MyJumpPage.aspx?URL=www.google.com
So, in your code, all you have to do is grab that 1st parameter, and then run code to jump/navigate to that page.
EG:
string strURL = "";
strURL = Request.QueryString("URL");
Response.Redirect("http://" + strURL);
So, the code behind a button, or even on page load can simply pull the query value from the url string, and then jump to that URL.

Access request after upload (ASP classic)

So, as I figured out, when I have a form with enctype="multipart/form-data" and I upload a file, I can no longer access the object request. The following error is shown:
Cannot use the generic Request collection after calling BinaryRead.
After checking some resources, I stumpled upon a statement, which says: "This is by design". Well, okay, not here to judge about design-decisions.
To give you a quick overview, let me walk you through the code:
if request("todo") = "add" then
Set Form = New ASPForm
category = request("category")
title = request("title")
if len(Form("upload_file").FileName) > 0 then
filename = Form("upload_file").FileName
DestinationPath = Server.mapPath("personal/allrounder/dokumente/")
Form.Files.Save DestinationPath
end if
end if
Nothing too special here so far. Later however, when I try to access my request object, the error mentioned above occures:
<% if request("todo") = "new" then %>
...
My question now, how to get rid of it or fix this. I don't want to open the upload in a popup if there is another way around. This is the only solution I could think off.
Perfectly would be an object, which checks Form and request. Alternatively maybe a check at the top of the file, which object I have to use?
Thanks for any suggestions.
There used to be a very popular ASP class/component that solved ASP file uploads. The site for that component has been taken down, but the code is mirrored here:
https://github.com/romuloalves/free-asp-upload
You can include this ASP page on your own page, and on your page instantiate the class to get access to the files in your form, but also to the form variables. Here is a piece of example code (Upload.Form accesses the form fields):
Dim uploadsDir : uploadsDir = server.mapPath(".") ' whatever you want
Dim Upload, ks, fileKey, mailto
Set Upload = New FreeASPUpload
call Upload.Save(uploadsDir)
ks = Upload.UploadedFiles.keys
for each fileKey in ks
Response.write(fileKey & " : " & Upload.UploadedFiles(fileKey).FileName & "<br/>")
next
mailto = Upload.form("mailTo")
Set Upload = Nothing
If you want to stick to your own implementation, you can probably figure out how to get to the form variables in a multipart/form-data encoded data stream by having a look at the code they use to do so.

Illegal characters in path asp.net and utf

i want get content of web page but when try to access it show this error
"Illegal characters in path"
my question is how i solve it and there is a better way to get content of a page
now i get content with windows application and webbrowser and have no error but cant do in asp
my code
Dim client As New Net.WebClient
TextBox1.Text = client.DownloadString("www.url.com/")
and content of page is
20141105#5058.00#4850.00#4997.00#4870.00#4920.00#4880.00#13553984180.00#2712255#495;
if i change url to http://www.url.com/ the problem solve but character not support like
`‹�طG[T�ے-تAہ0ءI±°M/ùے«Z✖پ$¼×ى(م´;اy­iص)—½؛‚C%%û`
and i add this code but nor work
client.Encoding = Encoding.UTF8
You should include http:// along with the URL to execute the query(TextBox1.Text = client.DownloadString("www.url.com/")) properly, so your code will be like the following:
Dim client As New Net.WebClient
TextBox1.Text = client.DownloadString("http://url.com/")

ASP.NET - Current name of page from web user control?

I need to find out name of location where web user control is. Somethnig like HttpContext.Current.Request.Url.ToString(), but I get only page for this web user control.
Request.Url.Segments will give you a string array. The last item is the page
You should try the Request.Url.LocalPath property
string fileNameFromLocalPath = Path.GetFileName(Request.Url.LocalPath);
This code helps:
string filename = Path.GetFileName(Request.Url.AbsolutePath);
If you ask for Page.getType.name, you will get the name of the master, the aspx page.
if you want the name of the ascx control you are working on, use
me.GetType.Name.ToString
if your control is in a directory MyDir and the name of your ascx is test.ascx then the result will be
"ASP.MyDir_test_ascx"
You can also use (VB.Net):
Dim pageName as String = Page.GetType().Name
which replaces the .extension with an underscore
So from Default.aspx you would be returned Default_aspx
You can also use:
Dim pageName as String = CType(HttpContext.Current.CurrentHandler, Page).GetType().Name
Which will produce the same results as described above.

Asp.Net System.Web.Routing Find actual .aspx Page

I'm using System.Web.Routing to have some better URL's and have come across a problem. I need to know the actual page that's handling the request.
for example a request comes in as:
/basketball/home
I need to find the page that handles that request, like:
/management/default.aspx
I'm only using the System.Web.Routing and not MVC. I have a handle to the RequestContext that contains some of the route information, but i don't see what i need.
Thanks in advance.
******* UPDATE *******
I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.
There is actually another simple way to get the actual page:
String vPath = ((System.Web.Routing.PageRouteHandler)Page.RouteData.RouteHandler).VirtualPath
Do not forget to check Page.RouteData.RouteHandler is not null - while you are getting the page w/o ASP.Net routing but directly.
Can you not retrieve this from the current HttpContext object?
Perhaps something like this:
public string GetCurrentPageName()
{
string sPath = System.Web.HttpContext.Current.Request.Url.AbsolutePath;
System.IO.FileInfo oInfo = new System.IO.FileInfo(sPath);
string sRet = oInfo.Name;
return sRet;
}
UPDATE:
Have you tried this article?
How to: Construct a URL from a Route
You should be able to retrieve it back from the Routing table you have constructed.
vhinn terrible's answer worked...
Page.AppRelativeVirtualPath
You just have to remove the initial tilde ("~"), and you're ready to go.
var path = Page.AppRelativeVirtualPath.Replace("~", String.Empty);
I don't know why it was downvoted. Worked for me like a charm.
Try using this code:
Page.AppRelativeVirtualPath
I was able to use Context.CurrentHandler which give me "ASP.management_default_aspx", not exactly the page but enough to get the page name.

Resources