How can i solve these ASP redirect error? - asp-classic

I put these sentence on the top of index.asp file
<% RESPONSE.REDIRECT "URL" %>
I've faced error
I also tried to put these sentence on the top of index.asp file
#include virtual=".\ssl.asp"
as remark
and made ssl.asp file with these datas

Your question is not clear. It may cover two realities :
Using <% RESPONSE.REDIRECT "URL" %> won't work because "URL" is a string not containing a valid url.
If you want to redirect to a valid url that is defined in a String variable named URL, then you would have to use something like :
Dim URL
URL = "https://somwhere.yourwebsite.com/yourpage.asp"
RESPONSE.REDIRECT URL

Related

Passing a variable in ASP using reponse redirect

I'm trying to pass a variable using Response.Redirect I have a page that I'm processing the info on which contains:
divrec = request.QueryString("div")
divstring = "divisions.asp?"&divrec
Response.Redirect divstring
But when I try to retrieve the information in another page by using
<% divrec = request.QueryString("div")
%>
<% =divrec %>
The variable/string does not display
i think you missed the querystring parameter in your divstring variable.
Try this:
divstring = "divisions.asp?div="&divrec
You should be able to access the parameter in the receiving page now.
What you could do is get the parameter from the url.
So if you redirected the user to www.mysite.com/divisions.asp?something
You could parse it up to the ? and get everything after it.
Try looking at http://www.powerasp.net/content/new/get-current-page-url.asp
Also this page might help you out
how to pass values from one page to other?

classic asp response.redirect to appropriate page

I created a .html maintenance file and I want when someone goes to the site to redirect to the maintenance folder/index.html
my code: (default.asp at the root)
<%
If InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("abc.com") ) > 0 Then
Response.Redirect("/maintenance/")
ElseIf InStr( UCase(Request.ServerVariables("SERVER_NAME")), UCase("web.com") ) > 0 Then
Response.Redirect("/web/")
End If
%>
it works fine, if I go to abc.com but if I type in abc.com/blog it goes to the blog page. how do I prevent so it doesn't go to any sub folders.
Maybe using Request.ServerVariables["HTTP_HOST"] can solve your problem.
Have you tried to look in the variable Request.ServerVariables("SERVER_NAME") with a Response.Write in order to see why the check on the string fails?
Are you using this "test > do" method instead of just taking the site down and creating a custom 404.html page because:
(1) Your site receives calls via various domain names and you want some to work but not others; or
(2) You just didn't think of using the 404 method?
Anyway, if you want to do it via code, then put this at the very top (before header-very important) of a page or even use this AS your index.asp or default.asp page:
<%
s_url = Request.ServerVariables("server_name")
s_url = lcase(s_url)
b_found = InStr(1,s_url, "abc.com",1)
if (b_found <> 0) then
response.redirect("/maintenance/")
end if
%>

Unable Response.Redirect(url); with many query arguments

The '&' that separates query string arguments is getting encoded no mater what I do.
// sitecore ASP.NET server side ascx code...
string url = string.Format("http://other-domain.com/?a={0}&b={1}", "1", "2");
Response.Redirect(url);
// ...
gives my browser the address:
http://other-domain.com/?a=1&b=2
which is not what I want, I simply want:
http://other-domain.com/?a=1&b=2
Is it Response.Redirect() that is HTMLencoding my '&'?
And how do I get it to leave that separator alone?
I am certain of one thing: this is not caused by Response.Redirect() or any of the other code that you posted.
There is probably something else wrong in the actual code.

ASP MVC ActionLink causes invalid URL

Using the standard route pattern
{controller}/{action}/{code}
and then a standard ActionLink in my view
<%: ActionLink("Details", "Details", new { code = item.Code }) %>
When the user has entered "N/A" as their code I see the following URL
http://localhost/AbsenceCode/Details/N/A
When I expect to see this
http://locahost/AbsenceCode/Details/N%2FA
Also, if the user has "A:B" as their code I see the correct URL (colon is url escaped) but I get a "400 bad request" from the server.
Does anyone have solutions to these problems? I cannot force the customer to use URL safe characters only.
Try
<%: Html.ActionLink("Details", "Details", new { code = Url.Encode(item.Code) }) &>
I've come up with a solution, source code is available here:
https://mrpmorris.blogspot.com/2012/08/asp-mvc-encoding-route-values.html

Url Rewriting in asp.net but maintaining the original url

Page aspxHandler = (Page)PageParser.GetCompiledPageInstance(virtualPath, context.Server.MapPath(virtualPath), context);
aspxHandler.PreRenderComplete += AspxPage_PreRenderComplete;
aspxHandler.ProcessRequest(context);
When you call Page.Request.Url after this, you get the Url of the page you rewrote to
...what I'm looking for is to do a rewrite, but for Page.Request.Url to remain as the original url that was passed in. Is that possible?
I had a similar problem using rewriting rules in the web.config. Not sure if this will solve your problem too, but I found that when the url was rewritten, the originally requested URL was accessible through the "HTTP_X_ORIGINAL_URL" server variable.
VB:
string pathAndQuery = Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL") ? Request.ServerVariables("HTTP_X_ORIGINAL_URL") : Request.Url.PathAndQuery
c#:
string pathAndQuery = Request.ServerVariables.AllKeys.Contains("HTTP_X_ORIGINAL_URL") ? Request.ServerVariables["HTTP_X_ORIGINAL_URL"] : Request.Url.PathAndQuery;
That should get you the original path and querystring of the request before rewriting, whether or not rewriting has taken place.

Resources