Answered by:
change the user agent

Question
-
User1024191908 posted
I have made a class that inherits from IHttpModule and set an event like below:
public void Init(HttpApplication app) { app.BeginRequest += new EventHandler(BeginReq); } public void BeginReq(object sender,EventArgs e) { NameValueCollection headers = HttpContext.Current.Request.Headers; headers.Remove("User-Agent"); headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"); }
but when I check the user agent in my default.aspx page:
string agent = Request.UserAgent;
It is still not what I have manually set.
what did I do wrong?
thanks in advance.
Sunday, April 22, 2018 6:19 AM
Answers
-
User753101303 posted
It tells how you are trying to solve some kind of problem rather than really which problem you are trying to solve. If you have some kind of HTML rendering issue with web forms using https://msdn.microsoft.com/en-us/library/ms228122(v=vs.100).aspx would be likely best rather than to pretend that each and every browser that hits your web site is Microsoft Edge.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 23, 2018 11:45 AM
All replies
-
User-369506445 posted
hi
you can define that in your Global file , please below code in your Global.asax
public class Global : HttpApplication { protected void Application_BeginRequest(object sender, EventArgs e) { NameValueCollection headers = HttpContext.Current.Request.Headers; headers.Remove("User-Agent"); headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"); } }
and for each request first that method and you can put a break-point and try it.
Sunday, April 22, 2018 7:03 AM -
User1024191908 posted
I works.
now when I check the Request.Headers i see it is set.
but when I check the Request.UserAgent it is the same old value.
why?
Sunday, April 22, 2018 7:26 AM -
User-369506445 posted
I didn't get your mean . if your mean is that user agent never change . you can debug it . I try that and it change . if your mean is another ,Please explain more details about your problem
you con try the below code :
protected void Page_Load(object sender, EventArgs e) { NameValueCollection headers = HttpContext.Current.Request.Headers; var agent = headers["User-Agent"]; Response.Write(agent); }
Sunday, April 22, 2018 7:42 AM -
User475983607 posted
The user agent comes from the client. Can you explain the problem you are trying to solve as it does not make sense to change the HTTP request.Sunday, April 22, 2018 12:55 PM -
User1024191908 posted
I wanted to programatically do something like Emulation of Edge so the user agent sent to the server is what I want not the real one.
Monday, April 23, 2018 11:38 AM -
User753101303 posted
It tells how you are trying to solve some kind of problem rather than really which problem you are trying to solve. If you have some kind of HTML rendering issue with web forms using https://msdn.microsoft.com/en-us/library/ms228122(v=vs.100).aspx would be likely best rather than to pretend that each and every browser that hits your web site is Microsoft Edge.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 23, 2018 11:45 AM -
User475983607 posted
anooshiravan
I wanted to programatically do something like Emulation of Edge so the user agent sent to the server is what I want not the real one.
The approach does NOT emulate Edge. It masks the user agent. Emulating Edge by either simply using Edge, an emulator, or create a craft code to send the user agent. Try using Dev Tools.
Monday, April 23, 2018 11:57 AM