c# - Session Expired in selenium IE webdriver - c#

I have a secured site from which I need to scrape data from some particular pages. The page should be opened strictly on IE. I opened the login page from selenium and pass the handle to the webdriver. Then the user surfs various pages and pop ups of that website. A timer runs and it is checked whether a particular page is opened or not. That is being checked with following code.
var windowIterator = driver.WindowHandles;
foreach (var windowHandle in windowIterator)
{
popup = driver.SwitchTo().Window(windowHandle);
if (popup.Title == PageTitle) //PageTitle is string value and is saved in App Config
{
doWork = true; //Scraping would be started on this page
break;
}
}
It is working perfectly for other sites in testing environment. In live environment the pop page is displaying with the session expired message and asking for user credentials. Once that is given then it is working fine. The architecture of the website that is being scraped is unknown to me.
Could any body tell me why this is happening and what is the way out.

Possibly its takes too much of the time to scrap the data before page will be updated/changed.
I believe site give to your browser one-session-cookes. Check all of cookies that site gaves you. Possibly this can be resolved by cookies edit via selenium. If not -- you can refresh the page in smaller than life time of cookies and show to the server that "user is here" =)

Related

Session does not work if higher .net version asp page is loaded in iframe of lower version page [duplicate]

I am working with provider hosted app using MVC with JQuery and have a requirement to show Provider Hosted App in an iframe in a SharePoint page to make it look like it is integrated in SharePoint. This application contains a report viewer(version 10.0.0.0) which is showing 'Asp.net session has expired or could not be found' when viewed in IE10 or higher. This app in a SharePoint page works fine when viewed in any other browser(Chrome, Mozilla) but not in IE.
Observations:
When the application is running directly in the Browser i.e.without using iframe, it is working fine.
When the Sharepoint page is viewed after opening the application directly in the browser i.e. in different tab, it works without any error.
But when viewed opening browser for the first time and no instances of the application are opened directly in the browser, it shows the error:
'Asp.net session has expired or could not be found'
Things already tried:
Increasing timeout for iframe as well as application in web.config file.
Setting report Viewer's KeepSessionAlive and AsyncRendering to false as well as true.
Reporting server timeout and all configurations.
Using sessionMode to InProc, SQLServer.
setting cookieeLess to true.
None of these are working for my scenario and I am struggling with this for a week. It seems like some registering problem at the first time and when the application is directly opened it gets registered and works. Any help will be highly appreciated.
P.S.: I have registered the report viewer in web.config file.
Thanks.
So guys finally i fixed my own issue. Thanks to the hint provided by mwwallace8 in the comments.
Problem: IE doesn't allow us to store third party session data in the form of cookies. This is because it gives lower level of trust to iframe pages, thus no session data for iframe will be stored in cookies. So when we submit the form and make a post call the server doesn't receive any session data in the request and thinks that it is the first request. This process generates a new Session ID and sends it back in the response. When the response comes back, the Session ID in the response and the is the new one and it thinks that the previous session expired.This generates the above problem.
Unlike when we open the application directly in the new tab, it takes it like first party and stores its session data in the form of cookies.
Because of this once we open the app in new tab directly, everything was working flawlessly.
Solution: IE needs P3P headers(Platform for Privacy Preference Project) to authenticate the session running in the iframe. This header will tell about what is the intent of the iframe session and what kind of data it will take from browser cookies. It is kind of swiping the Access card before entering in an IT company. So the question is how to generate this P3P header? The answer is here: Go to web.config file and add this code in Configuration tag
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="p3p" value="CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT""/>
</customHeaders>
</httpProtocol>
</system.webServer>
This will create a header certificate i.e. P3P header certificate which will authenticate the iframe session data to get stored in the browser cookies.
To know what these value actually means, go to This Link. You will find a whole lot of information about P3P headers in here.
Hope this might help someone.
Cheers..

IE failed to redirect the page

I have got a problem that I am redirecting the page to other domain using response.redirect, It works well in Firefox, but in ie it shows the blank web page. when i tried to see what happens in fiddler, it says that object Moved, but the redirect doesn't happens here. Interesting thing is I couldn't replicate this in my local environment, but it happens in my DEV and QAL servers.
When i tried in dev & QAL servers, IE redirects it to the desired page.Can anyone help??
Try to clear cache in Internet Explorer
You probably set redirect to some page and then change it to other page.
Sometimes when permanent redirect occurs, IE cache it and don't ask for a page one more time but get the redirect path from cache. IE don't even refresh the address textbox which is misleading.

Redirect to Browsers Homepage

I am working on an asp.NET 4.0 Web Application, using C#. I would like to redirect the user to the homepage of his browser. Is this possible?
This will be done because internally we are using an intranet, and we would like to make it redirect to that intranet without having to hard code it and since the homepage is by default the url of the intranet, it would be better if we could use the homepage instead of hardcoding it.
EDIT:
We are using IE here, and will not change most probably as that is the standard. So as long as it works with all IE Versions, it's fine.
Use Javascript to return to the user's home page,
e.g.
function goHome(){
if (window.home) {
window.home();
} else {
window.location = "about:home";
}
}
and then call the JS goHome() function somewhere on the page (or even on a hyperlink).
As stated above, use the about:home uri.
Another solution would be to store the intranet url in the web.config and use this value. Then if it ever changes you will only need to change it in one place.
As far as i know it is not possible (been researched alot). But if all homepages are the same why not simply use META REFRESH?
EDIT
Try linking to this: About:home
Go home!
worked for me in IE9
EDIT 2:
Sending user to their browser's Home Page using Javascript
This will get you started for firefox and safari
EDIT 3:
Response.Redirect("about:home", false);
You cannot redirect server side to a users homepage.
SERVER <> USER (server is not the user)
Therefore the server cannot know what the user's homepage is.
So if you you use some sort of javascript redirect, then you sort of can redirect to home, but its a little glitchy.
All in all there is no cross-browser way to redirect to a user's homepage.
You Can't!
You can't retrieve the user home page because of Security and Privacy issues, and there is no Cross-browser work around.
What you can?
You can redirect to any page, so you can simply redirect to your intranet home page.
its also more future proof so that if your intranet homepage changes you just have change to redirect to the new address instead of changing every single machines home page.

How do I redirect to a page after successful login?

I'm fairly new to web forms development, playing around with a project created using the ASP.NET Web Application template in VS 2010. After the user successfully logs in, I want the user redirected to a page I created. How do I modify my project to redirect the user after login? Any samples / tutorials / etc are greatly appreciated.
Thanks!
To simply redirect to a new page when your user has logged in, use the DestinationPageUrl property of your login control... assuming you're using the Login control that is.
If you need to do anything more advanced you can use the OnLoggedIn event handler for your Login control to perform a redirect manually, or add any code for event logging and such.
If you've rolled your own login control, and are just using things like text boxes and button controls, then in your Button_Click event, you can just use Response.Redirect("DestinationHere"); to take your users to a new page.
After you checked for login:
Response.Redirect("url");
I assume you're using ASP.NET Login control. There's a DestinationPageUrl property of that control that handles exactly that. If login was successfull user is redirected to URL provided in that property.
<asp:Login ID="Login1" runat="server" DestinationPageUrl="~/Admin/Default.aspx">
</asp:Login>
Go to Properties and Set DestinationPageUrl.
Server.Transfer( *url*) ?
(method on HttpServerUtility)
I know next to nothing about ASP.NET, but from my Java web developer daze, redirect is bad because it involves another network round trip to the browser and back when you really just want to continue processing in another page.
And Response.Redirect() really does issue a 302 response code ("try this other url instead") back to the browser. yuck. XP
Server.Transfer() looks like the java version of Response.Forward()
For Sharepoint farm solution development
Page.Response.Redirect("url");
The issue with Response.Redirect() is the 302. In some browsers (eg Chrome) this causes the new session cookie to be immediately invalidated.
In other words, using that method to redirect causes the user to no longer be logged in, so you did not accomplish your purpose!.

asp.net: data put in session is available while working in internet explorer but not in opera

it's a really weird thing - i have a website that works perfectly in maxthon (internet explorer based browser). i started it in opera and found out that the data put in the Session dictionary on one site, is not available on the other... i mean i have Welcome.aspx, where when you click next the following code is executed:
Session["sessionData"] = sessionData;
Response.Redirect("~/Models.aspx");
while debugging i can see that in models.aspx Session in empty when executing in opera but everything is fine when executing in maxthon.
has anyone got any idea what can be wrong? because i'm clueless.. is this some opera preferences thing or is it something in code?
Edit: i checked Session.IsNewSession and while executing in maxthon isnewsession is set to false but in opera it's true. it seems that in opera when moving to a new page it somehow creates new session...
If your write the session on the first hit then you should do
Response.Redirect("nextpage.asp", false);
Otherwise it wont write the whole responsestream and the cookie might not have been written. You can instead choose to have cookiless sessions. But then your open to session hijacking.
ASP.NET session is stored by a key that is saved as a cookie in the browser. Check Opera to see if it is accepting cookies - it will need to in order for ASP.NET session to work properly.
Maybe you have cookies disabled in Opera. Session works (unless speciefies as cookieless in web.config) by storing an identifier in a cookie. If the brwoser does not allow the access, the server won't be able to locate the data

Categories

Resources