Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Javascript and asp.net redirect

  Asked By: Alisha    Date: Mar 18    Category: Sharepoint    Views: 3180

Redirecting a user looks simple at first, but with our company's unique
situation of having two un-trusted domains and using ADFS to bouncing around
thru firewalls and multiple servers, etc. I have tried using Response.Redirect
FAILED, Tried Server.Transfer FAILED, window.location worked great!!! But does
not solve my situation because I need to grab specifically the URL the user is
trying to go to!!!

Scenario:

Using SharePoint for intranet, we have dual domains and no trust between them
EXCEPT for the ADFS servers which I think is what is killing the
response.redirect, one side uses httpS and the other side does not!!! So when
users type in http://mydomain.com<http" target="_blank" rel="nofollow">http://mydomain.com<http://mydomain.com/> and there suppose to
type httpS://mydomain.com<https://mydomain.com/> they get a 404 error company
wants this to be automatically fixed!!! Well my task is to right a script that
gets there IP address and if it matches the side that is suppose to have httpS
but doesn't rebuild the requested URL and add the S! No big deal until, you
through in the dual domains, ADFS, and SharePoint! (Trying to place asp.net
script into Master page so that all sites that is hit works until it try's to
redirect)

My problem is that the user's browser has to make the request to the server for
httpS for the ADFS and network not to kill it (I'm assuming this is why its
failing script works fine for users on the same domain as the server resides) in
comes JavaScript's window.location="http://mydomain.com" works great, but I need
to rebuild the URL they requested dynamically and in asp.net I was pulling IIS
variables to build this string worked great even got the query string variables
(and yes I need those too!) but not sure what I need or if it is even possible
to do in JavaScript or Even if I can Mix the two???????? Need some serious help
on this one!!!

Here is what the script I wrote looked like in ASP.NET (Ignore the first fifty
million if statements they were just to see what the IIS Variables contained so
I could rebuild the URL):


<script runat="server">


protected void Page_Load(object sender, EventArgs e)
{
String _str_RedirectTo = "NOT WORKING";
String _ALL_HTTP = Request.ServerVariables["ALL_HTTP"];
String _ALL_RAW = Request.ServerVariables["ALL_RAW"];
String _APP_POOL_ID = Request.ServerVariables["APP_POOL_ID"];
String _APPL_MD_PATH = Request.ServerVariables["APPL_MD_PATH"];
String _APPL_PHYSICAL_PATH =
Request.ServerVariables["APPL_PHYSICAL_PATH"];
String _AUTH_PASSWORD = Request.ServerVariables["AUTH_PASSWORD"];
String _AUTH_TYPE = Request.ServerVariables["AUTH_TYPE"];
String _AUTH_USER = Request.ServerVariables["AUTH_USER"];
String _CACHE_URL = Request.ServerVariables["CACHE_URL"];
String _CERT_COOKIE = Request.ServerVariables["CERT_COOKIE"];
String _CERT_FLAGS = Request.ServerVariables["CERT_FLAGS "];
String _CERT_ISSUER = Request.ServerVariables["CERT_ISSUER"];
String _CERT_KEYSIZE = Request.ServerVariables["CERT_KEYSIZE"];
String _CERT_SECRETKEYSIZE =
Request.ServerVariables["CERT_SECRETKEYSIZE"];
String _CERT_SERIALNUMBER =
Request.ServerVariables["CERT_SERIALNUMBER"];
String _CERT_SERVER_ISSUER =
Request.ServerVariables["CERT_SERVER_ISSUER"];
String _CERT_SERVER_SUBJECT =
Request.ServerVariables["CERT_SERVER_SUBJECT"];
String _CERT_SUBJECT = Request.ServerVariables["CERT_SUBJECT"];
String _CONTENT_LENGTH = Request.ServerVariables["CONTENT_LENGTH"];
String _CONTENT_TYPE = Request.ServerVariables["CONTENT_TYPE"];
String _GATEWAY_INTERFACE =
Request.ServerVariables["GATEWAY_INTERFACE"];
String _HTTP_ACCEPT = Request.ServerVariables["HTTP_ACCEPT"];
String _HTTP_ACCEPT_ENCODING =
Request.ServerVariables["HTTP_ACCEPT_ENCODING"];
String _HTTP_ACCEPT_LANGUAGE =
Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"];
String _HTTP_CONNECTION =
Request.ServerVariables["HTTP_CONNECTION"];
String _HTTP_COOKIE = Request.ServerVariables["HTTP_COOKIE"];
String _HTTP_HOST = Request.ServerVariables["HTTP_HOST"];
String _HTTP_METHOD = Request.ServerVariables["HTTP_METHOD"];
String _HTTP_REFERER = Request.ServerVariables["HTTP_REFERER"];
String _HTTP_URL = Request.ServerVariables["HTTP_URL"];
String _HTTP_USER_AGENT =
Request.ServerVariables["HTTP_USER_AGENT"];
String _HTTP_VERSION = Request.ServerVariables["HTTP_VERSION"];
String _HTTPS = Request.ServerVariables["HTTPS"];
String _HTTPS_KEYSIZE = Request.ServerVariables["HTTPS_KEYSIZE"];
String _HTTPS_SECRETKEYSIZE =
Request.ServerVariables["HTTPS_SECRETKEYSIZE"];
String _HTTPS_SERVER_ISSUER =
Request.ServerVariables["HTTPS_SERVER_ISSUER"];
String _HTTPS_SERVER_SUBJECT =
Request.ServerVariables["HTTPS_SERVER_SUBJECT"];
String _INSTANCE_ID = Request.ServerVariables["INSTANCE_ID"];
String _INSTANCE_META_PATH =
Request.ServerVariables["INSTANCE_META_PATH"];
String _LOCAL_ADDR = Request.ServerVariables["LOCAL_ADDR"];
String _LOGON_USER = Request.ServerVariables["LOGON_USER"];
String _PATH_INFO = Request.ServerVariables["PATH_INFO"];
String _PATH_TRANSLATED =
Request.ServerVariables["PATH_TRANSLATED"];
String _QUERY_STRING = Request.ServerVariables["QUERY_STRING"];
String _REMOTE_ADDR = Request.ServerVariables["REMOTE_ADDR"];
String _REMOTE_HOST = Request.ServerVariables["REMOTE_HOST"];
String _REMOTE_PORT = Request.ServerVariables["REMOTE_PORT"];
String _REMOTE_USER = Request.ServerVariables["REMOTE_USER"];
String _REQUEST_METHOD = Request.ServerVariables["REQUEST_METHOD"];
String _SCRIPT_NAME = Request.ServerVariables["SCRIPT_NAME"];
String _SCRIPT_TRANSLATED =
Request.ServerVariables["SCRIPT_TRANSLATED"];
String _SERVER_NAME = Request.ServerVariables["SERVER_NAME"];
String _SERVER_PORT = Request.ServerVariables["SERVER_PORT"];
String _SERVER_PORT_SECURE =
Request.ServerVariables["SERVER_PORT_SECURE"];
String _SERVER_PROTOCOL =
Request.ServerVariables["SERVER_PROTOCOL"];
String _SERVER_SOFTWARE =
Request.ServerVariables["SERVER_SOFTWARE"];
String _SSI_EXEC_DISABLED =
Request.ServerVariables["SSI_EXEC_DISABLED"];
String _UNENCODED_URL = Request.ServerVariables["UNENCODED_URL"];
String _UNMAPPED_REMOTE_USER =
Request.ServerVariables["UNMAPPED_REMOTE_USER"];
String _URL = Request.ServerVariables["URL"];
String _URL_PATH_INFO = Request.ServerVariables["URL_PATH_INFO"];




if (_ALL_HTTP != null)
{
Response.Write("ALL_HTTP");
Response.Write("<br>");

Response.Write(_ALL_HTTP.ToString());
Response.Write("<br>");
}

if (_ALL_RAW != null)
{
Response.Write("ALL_RAW");
Response.Write("<br>");

Response.Write(_ALL_RAW.ToString());
Response.Write("<br>");
}

if (_APP_POOL_ID != null)
{
Response.Write("APP_POOL_ID");
Response.Write("<br>");

Response.Write(_APP_POOL_ID.ToString());
Response.Write("<br>");
}

if (_APPL_MD_PATH != null)
{
Response.Write("APPL_MD_PATH");
Response.Write("<br>");

Response.Write(_APPL_MD_PATH.ToString());
Response.Write("<br>");
}

if (_APPL_PHYSICAL_PATH != null)
{
Response.Write("APPL_PHYSICAL_PATH");
Response.Write("<br>");

Response.Write(_APPL_PHYSICAL_PATH.ToString());
Response.Write("<br>");
}

if (_AUTH_PASSWORD != null)
{
Response.Write("AUTH_PASSWORD");
Response.Write("<br>");

Response.Write(_AUTH_PASSWORD.ToString());
Response.Write("<br>");
}

if (_AUTH_TYPE != null)
{
Response.Write("AUTH_TYPE");
Response.Write("<br>");

Response.Write(_AUTH_TYPE.ToString());
Response.Write("<br>");
}

if (_AUTH_USER != null)
{
Response.Write("AUTH_USER");
Response.Write("<br>");

Response.Write(_AUTH_USER.ToString());
Response.Write("<br>");
}

if (_CACHE_URL != null)
{
Response.Write("CACHE_URL");
Response.Write("<br>");

Response.Write(_CACHE_URL.ToString());
Response.Write("<br>");
}

if (_CERT_COOKIE != null)
{
Response.Write("CERT_COOKIE");
Response.Write("<br>");

Response.Write(_CERT_COOKIE.ToString());
Response.Write("<br>");
}

if (_CERT_FLAGS != null)
{
Response.Write("CERT_FLAGS");
Response.Write("<br>");

Response.Write(_CERT_FLAGS.ToString());
Response.Write("<br>");
}

if (_CERT_ISSUER != null)
{
Response.Write("CERT_ISSUER");
Response.Write("<br>");

Response.Write(_CERT_ISSUER.ToString());
Response.Write("<br>");
}

if (_CERT_KEYSIZE != null)
{
Response.Write("CERT_KEYSIZE");
Response.Write("<br>");

Response.Write(_CERT_KEYSIZE.ToString());
Response.Write("<br>");
}

if (_CERT_SECRETKEYSIZE != null)
{
Response.Write("_CERT_SECRETKEYSIZE");
Response.Write("<br>");

Response.Write(_CERT_SECRETKEYSIZE.ToString());
Response.Write("<br>");
}

if (_CERT_SERIALNUMBER != null)
{
Response.Write("CERT_SERIALNUMBER");
Response.Write("<br>");

Response.Write(_CERT_SERIALNUMBER.ToString());
Response.Write("<br>");
}
.
.
.
.
.
.
.
.
if (_URL != null)
{
Response.Write("URL");
Response.Write("<br>");

Response.Write(_URL.ToString());
Response.Write("<br>");
}

if (_URL_PATH_INFO != null)
{
Response.Write("URL_PATH_INFO");
Response.Write("<br>");

Response.Write(_URL_PATH_INFO.ToString());
Response.Write("<br>");
}

//This is the Guts of the and Glory of the of the string build and
redirect
//Checks IP match and if they have requested http instead of https
TRUE then rebuilds request not then do nothing

if (_REMOTE_ADDR =="127.0.0.1" &&
_SERVER_PROTOCOL.Substring(0,5).ToUpper() == "HTTP/")
{
_str_RedirectTo = @"https://" + _SERVER_NAME.ToString() +
_URL.ToString();
if ((_QUERY_STRING != null || _QUERY_STRING != string.Empty ||
_QUERY_STRING != "" || _QUERY_STRING!=" ") && _QUERY_STRING.Length > 1)
{
_str_RedirectTo += @"?" + _QUERY_STRING.ToString();
}
Response.Write(@"<br />");
Response.Write(_REMOTE_ADDR.ToString()+ " URL TO Go To
"+ _str_RedirectTo.ToString());
Response.Write(@"<br />");
Response.Redirect(_str_RedirectTo.ToString());
}
}

</script>

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on Javascript and asp.net redirect Or get search suggestion and latest updates.




Tagged: