1

in My Scenario.

I want to redirect all request to another domain that includes Path,QueryStrings,Method,Content

Example Some user send request to my domain.

POST www.mydomain.com/service?id=5
HEADER { 
token:securityToken
UserAgent: Chrome
Accept: application/json
}
BODY
{
Content lorem ipsum
}

I 'll Check some parameters and change token in the header.

Then

I want to send this request to another domain.

POST www.anotherdomain.com/service?id=5
HEADER {
token:newsecurityToken
UserAgent: Chrome
Accept: application/json
}
BODY
{
Content lorem ipsum
}

Finally

User will get anotherdomain's response. Is it Possible ?

Server : Windows server 2008 .Net Framework : 4.0

Thanks

usr
  • 168,620
  • 35
  • 240
  • 369
halit
  • 1,128
  • 1
  • 11
  • 27

2 Answers2

2

If you want to make the request come back through your domain, your best bet would be to make a request of your own to the external domain. I'd give more details about how, but I don't know what version of .net you are using. Here is one post that outlines a method.

Relaying a request in asp.net (Forwarding a request)

It basically says to create a new WebRequest, set the relevant properties, get the response, and send the information from the response back to the user.

I kind of feel like I have to ask this, are you sure you aren't trying to phish or something? On second thought, never mind. ;)

Update:

Since you don't need it to go through your domain, I would recommend using a 301 redirect. Here's a post where someone does it in begin request

301 redirect in asp.net 4.0

void Application_BeginRequest(object sender, EventArgs e) 
{
    // Code that runs on every request
    if (HttpContext.Current.Request.Url.ToString().ToLower().Contains("http://website.net"))
    {
        HttpContext.Current.Response.Status = "301 Moved Permanently";
        HttpContext.Current.Response.AddHeader("Location", Request.Url.ToString().ToLower().Replace("http://website.net", "http://www.website.net"));
    }
}

Note that this post also offers a way to do it through url rewriting in web.config if there isn't any complicated logic to determine if you want to redirect.

Community
  • 1
  • 1
parKing
  • 677
  • 3
  • 13
  • Thanks for answer. this topic helps me. Could I use that codes in global.asax > begin_request . But Path and Querystring are missing. I can add this properties to request. And Framework version is 4.0, Request doesn't have to comeback through my domain. – halit Feb 22 '13 at 21:44
  • If it doesn't have to come back through your domain, then I would absolutely just 301 redirect them – parKing Feb 22 '13 at 21:58
  • How can I do it, after audit request ? I shouldn't use IIS redirection. – halit Feb 22 '13 at 22:00
  • I tried to use 301 redirect. But it converts post request to get request. and There is no Request body and custom Headers. :( – halit Feb 22 '13 at 22:16
  • I fixed my problem . Solution is on the first linq what @parKing shared (Relaying a Request in Asp.net) – halit Feb 23 '13 at 02:28
0

Just to throw an idea out because I've never seen this approach before, is there a reason you can't use SOAP webservices to accomplish this?

pass values to an object to webservices webmethod C#

They were more or less created for this type of thing and would make your life a whole lot easier. Otherwise, you can use URL parameters

Asp.net adding parameter to url string

Or, just pass the values using POST & GET requests appropriately. POST to domain B & have a listener waiting for that POST that will parse those values. I'd go with the web services, they're easier than they look.

Community
  • 1
  • 1
RandomUs1r
  • 4,010
  • 1
  • 24
  • 44
  • None of them, There is an API like Facebook API. I have a lot of client projects which uses this API. So , I need to audit this client projects Like Read Data Limit , Write Data Limit. I 'll take all request, then I 'll send to facebook API after audit. – halit Feb 22 '13 at 21:57
  • Interesting so let's see if I'm understanding this correct. FB API > client app > you > FB API? – RandomUs1r Feb 22 '13 at 22:09
  • Yes you are right. myAPI should be between myclientprojects and facebookAPI. MyAPI will control everything. – halit Feb 22 '13 at 22:14