I have inherited a project written in .net webforms, basically just an old site that needed to be skinned/made responsive. All of that is done and functions as it should. However I noticed that the old version of the site didn't contain a 404 page, something that I feel is necessary for this site. I've made a 404 page but what I want to do is display the URL on the page. So it'd be something like
<div>
<h1>Something went wrong with</h1>
<h2>Page URL here</h2>
</div>
I know in MVC.net you can write http://www.domainname.com#(Request.QueryString["aspxerrorpath"]
but whats the equivalent in webforms?
FYI the "backend" of each page is written in VB
Thanks in advance
I originally misread your question and advised Server Variables for "URL", then realised you're on a custom error page, so it would just show the URL you're on.
Perhaps you can use the Referring page?
<%=Request.ServerVariables["HTTP_REFERER"]%>
Additional info
ASP.NET aspxerrorpath in URL
Related
I'm seeing some unexpected (to me) behavior when using asp-page in my asp.net Razor Pages application. I have a folder structure like this:
Manage
Index
NewAccount
On the NewAccount page, I want to have a link back to the manage account page, /Manage/Index. I'd expect the following code to do this:
<p><a asp-page="/Manage/Index" asp-route-accountId="#Model.AccountId">Back to account view</a></p>
Instead of linking to the /Manage/Index page though, it's linking me back to /Manage/NewAccount! This makes absolutely no sense to me.
I've tried quite a few values for asp-page.
/Manage/Index: Loads Manage/NewAccount as described
/Index: Loads /Index, which is what I'd expect
./Index: Loads /Index
/Manage: Routes to /Manage/NewAccount
I know I could get this working using regular HTML code. But I'm trying to do this using canonical asp.net syntax. Plus I'd really like to use asp-route to pass query parameters, which you can't use with href.
I'm sure the issue is obvious to those of you who know razor pages better than I. I'd love an explanation of why /Manage/Index doesn't work as well, if someone knows. Thanks!
I was assigned a project I'm having some difficulty finding a solution or guide to, we have a asp shopping cart that currently runs in a classic asp page, we want to redirect once they click "checkout" to redirect to our newer aspx page.
any help is greatly appreciated.
edit:
I have tried to simply do a redirect to the website giving it the information that it needs like order id, date, etc. however this method gives me an error with the web.config on the asp side. involving our target framework 4.5.2.
I am extremely new to web programming and this is my first non fix bug x issue.
If I understood your question correctly, you just need to put your destination page address in your action parameter in the original page <form> tag.
<form action="./destination_page.aspx">
<!-- page content -->
</form>
HI so i keep running across websites which when looked through or searched (using their own search function) return's a static URL ie.) ?id=16 or default.aspx no mater what page of the website you visit after the search has been performed. This becomes a problem when i want to go directly to a post/page within one of these sites so i'm wondering. If anyone knows How could i actually find out what the absolute URL is.
So that i can navigate straight to it. I'm not really familiar with coding but have tried looking in the page source but i wasn't really able to gleam anything from there.
The basics around asp.net urls: http://www.codeproject.com/Articles/142013/There-is-something-about-Paths-for-Asp-net-beginne
It all really depends on what you're trying to find, as far as finding a backway to locate a absolute path, is highly doubtful. If the owner of the site(most blogs) want you to have a perma link to a page, they use url-rewriting for putting things in the URI like title page and such. Alot of MVC sites do this now.
The '?id=16' you're seeing is just a query string, a holder for other logic they are doing.
I'm using webforms with UrlRewriting.Net to rewrite pages, e.g.
http://www.example.com/stuff.aspx?c=30
becomes
http://www.example.com/stuff/30-this-stuff.aspx.
It works in so far as the correct content is loading; however, none of the postbacks are working (mostly buttons on the page). If I set up a breakpoint on Page_Load, I see that IsPostBack is always false. Any ideas on how to fix this? Right now I'm just on Visual Studio 2008.
EDIT:
I have since switched to UrlRewriter.Net, which worked after a few tweaks (see Scott Gu's article). Besides here, I have posted my original problem to the developer's forum: if I ever get an answer, I'll post it here (unless else posts it here first).
You need to make sure it is doing something called ClientRebaseing which makes sure .NET is seeing the new URL vs the old Raw URL. See this post for more information:
http://www.ifinity.com.au/Blog/Technical_Blog/EntryId/46/Why-does-Url-Rewriting-break-all-my-image-links
Also I don't know if this is supported in UrlRewriting.NET, but my own URL Rewriter based off of Apache mod_rewrite does support rebasing the client path.
http://urlrewriter.codeplex.com
I could be way off here, but I worked on a project that used UrlRewriter.Net and from what I remember, I think the issue you're having is not rewriting the form element's action attribute. View your source and see if the URL in <form action"..." ... /> is the same as what's in your address bar. I don't know how we did this because it was at another job and the technical lead there wrote the code to do that, but I imagine you would change the rendering of the form tag.
This is actually a follow up on my previous question (link)
I've created the HttpHandler and it works fine for now, I'll add flexibility by using the querystring and session to point the post I'm making in the right direction.
The next question is as follows.
Now that I have the old page iframed as it should be, there's still the trouble of handling the postbacks (or actions) these pages trigger.
Every button action (asp form post) refers to a page that is not there (it's on the other server from which I am importing functionality).
I've tried using a url mapping to the other server but I get an error that tells me the external link is not a valid virtual directory. Hence I discarded this option.
I there anyway to keep functionality going inside the iframe?
please do ask clarification if you need it.
I got a solution from a colleague.
before passing the response string to the Iframe from the handler I use a string.replace to adjust the urls in the old site. This way they point to the old site and everything works again :)