I have a classic ASP page that requires two values from a form. These values are posted to the ASP page from another pages form. I would like to pass these values to the ASP page without the need for a form for testing. Is this possible?
This is what the asp page looks like:
<%#LANGUAGE="JavaScript"%>
<%
var someID = new String( Request.Form("someID") );
var anotherID = new String( Request.Form("anotherID") );
%>
Ideally I would like to have VS pass values to 'someID' and 'anotherID' when debugging is started.
There are plenty of command-line tools that can execute a POST request without building a form; the simplest one is probably cURL.
curl -d someID=someValue&anotherID=someOtherValue http://localhost/myASPPage.asp
You could probably do a static HTML page that references jQuery and the following script that will execute a post on page load
$(document).ready(function(){
$.post("[url to your page goes here]", { someID: "someValue", anotherID: "someValue2" } );
});
Or, you could set your variables to use Request.QueryString() during testing and then reference your ASP page with variables via a URL
<%#LANGUAGE="JavaScript"%>
<%
var someID = new String( Request.QueryString("someID") );
var anotherID = new String( Request.QueryString("anotherID") );
%>
URL
http://myhost.com/myASPPage.asp?someID=1&anotherID=2
You could probably do this from your C# code using the WebClient.UploadValues method:
http://msdn.microsoft.com/en-us/library/9w7b4fz7.aspx
If you need to actually redirect the user to your classic ASP page with the values posted, you might have more difficulty (all of the standard methods of redirecting via ASP.NET only do GET requests, but my understanding is that you will need a POST request for the values to go into the Request.Form collection on the classic ASP page). A Server.Transfer call might be able to do what you want, and I also found some code here that claims to be able to do that:
http://www.codeproject.com/KB/aspnet/ASP_NETRedirectAndPost.aspx
Related
In my jquery code, I can open a new action using the following code:
window.open("ControllerAction");
However, this opens the controller action in a different tab. How can I make this open in the same window without creating a separate tab.
This is basically a workaround I have found to doing page refresh in asp.net mvc.
You need to use Window.location
Though Window.location is a read-only Location object, you can also assign a DOMString to it. This means that you can work with location as if it were a string in most cases: location = 'http://www.example.com' is a synonym of location.href = 'http://www.example.com'
Basically you can use one of these, assign() and replace() navigates to the URL without adding a new record to the history. Here you find more: Window.location
var url = "/{controller}/{action}";
window.location.href = url;
window.location.assign(url);
window.location = url;
window.location.replace =url;
instead
window.open("ControllerAction");
Thanks for anyone who searched but I got it to work. Below code works.
window.location.replace("ControllerAction");
Response.Redirect("~/CustomList.aspx?id="+Data.Item1+"&type="+Data.Item2);
I am adding this from Codebehind Asp.net
However it isn't working
Getting this Error
This page can't be displayed
•Make sure the web address http://localhost:51955 is correct.
•Look for the page with your search engine.
•Refresh the page in a few minutes.
Could you try something like this ?
string parameter1 = HttpUtility.UrlEncode(Data.Item1)
string parameter2 = HttpUtility.UrlEncode(Data.Item2)
Response.Redirect("~/CustomList.aspx?id="+parameter1 +"&type="+parameter2 );
And make sure that page is in the root of your project, is this page is in another project, you will need to change the port in the URL. Localhost:port/CustomList.aspx
Trying to put together a quick and dirty page to redirect to another website in a new window.
So I stash a url in the session, redirect to the page from mvcSiteMap, hit the page...
run this javascript
$(document).ready(function () {
window.open( '#HttpContext.Current.Session["EisUrl"].ToString();' );
});
</script>
}
and instead of opening a new window pointing to google.com, I get the same window with this message.
The view 'http://google.com' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/ReportsManagement/http://google.com.aspx
~/Views/ReportsManagement/http://google.com.ascx
~/Views/Shared/http://google.com.aspx
~/Views/Shared/http://google.com.ascx
~/Views/ReportsManagement/http://google.com.cshtml
~/Views/ReportsManagement/http://google.com.vbhtml
~/Views/Shared/http://google.com.cshtml
~/Views/Shared/http://google.com.vbhtml
So it's treating my external URL as if it's still internal to the website...
This seems like it ought to be pretty simple..... clearly I'm missing something obvious.
Any Help is appreciated.
Make sure what is being rendered from the session is the correct and well-formed URL as you would expect. I normally use window.location to redirect in javascript also.
Maybe totally out of scope, but can't you do this in the ActionResult ?
return Redirect("http://www.google.com");
try
window.location = '#HttpContext.Current.Session["EisUrl"].ToString()';
I figured it out, i was being an id 10 t,
I had this in the view(razor)
#model string
and this in the controller
public ActionResult GetEisReportRedirect()
{
string url = eisReportBLLHdl.DoGetEisReportRedirect( );
return View( url );// i was passing url here to the view
}
So it' was trying to pass the string as a model, I decided i was unsure of the exact behavior and swapped to putting it in the session.. but left those in place.
For some reason, the string was getting interpteted as a URL, the fact that the new window was not openeing should have been a clue it was going off the rails early.
When I removed the line from the model and the url paramter from the return View()... it now redirects correctly (just not in a new page but I'll get that)
Thanks for all the help!
in my own site i need a thing that page are known by #topic.
it's need to look like
mywebsite.com#google [are this possible i need to pass google as parameter]
OR
mywebsite.com/#google [if first can not be done then how i can use it]
how i can apply this thing in my website. the thing i need to done that
if anyone open the site mywebsite.com#google that the content genrate dynamically through [passing google as parameter]
can anyone show how i can make routing for this
You can't use routing for this. The value that follows the # sign in an URL is NEVER sent to the server by the client browser. So for example if you request http://example.com/someaction#google the server can never fetch the value google simply because the browser never sends it. The only way is to use javascript (window.location.hash) and maybe send an AJAX request to the server by rewriting the url : http://example.com/someaction?param=google
You have the route table at Global.asax. Add this on the method RegisterRoutes. I am not so sure if it will work as I didn't test but that can give you a good start.
routes.MapRoute(
"RouteWithSharp",
"#{page}",
new { controller = "Home", action = "Index", page = "" } // Parameter defaults
);
Is there a way to use HTML.RouteLink() to add onto the existing url. For example I have
<%: Html.RouteLink(link.Text, link.RouteValues) %>
My controller is Pages, and my action is somestring. So the generated url would be
localhost/Page/somestring
This is fine. However I would link the generated url when I visit http://localhost:1241/Admin/ section to be
localhost/Admin/Page/somestring
Instead of
localhost/Page/somestring
This localhost/Page/somestring url is setup in my global.asx file to route to view a page, and the localhost/Admin/Page/somestring url is routed to edit the page.
I hope this is making sense and thank you all for your help!
Tyrone
Here Are my two routes which could give you some idea
routes.MapRoute(null,"Pages/{page}", new { controller = "Pages", action = "Page" });
routes.MapRoute("Edit Pages", "Admin/Page/{page}",new { controller = "Admin", action = "EditPage", id =UrlParameter.Optional });
You haven't really given enough information to answer this question thoroughly. As I understand it, you have a partial that uses the same code whether you're in the admin or not to generate the URL. But you want the same code to generate different URLs depending on whether you're in the admin or not.
The trick here is that you need the route values to match the defaults of the route you want to match.
In this case, to link to the non-admin:
Html.RouteLink(linkText, new {controller="Pages", action="Page", page = thePage})
But to link to the admin version
Html.RouteLink(linkText, new {controller="Admin", action="EditPage", page = thePage})
So what you need to do is make sure the partial gets the right values depending on which context it's being used in.