Regarding Session Timeout using selenium c# - c#

My Application has a Functionality which takes time to load the search results like more then a minute because of which my scripts fails and gives a 60 seconds session timeout error message. I googled few solutions and got one from stack overflow"How to set session timeout in web.config" but i am not sure where exactly to implement it. i have a file in my framework called "app.config" and the code in the app.config is below
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-11.0.0.0" newVersion="11.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
This Below mentioned code is given in the stack overflow to make necessary changes in web.config file to set the session timeout
<configuration>
<system.web>
<sessionState timeout="20"></sessionState>
</system.web>
</configuration>
please help me where to make the necessary changes in app.config file.

You could set an implicit wait for the driver in the following fashion:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
An implicit wait is to tell WebDriver to poll the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available. The default setting is 0. Once set, the implicit wait is set for the life of the WebDriver object instance.
Now the only reason to use app.config is if you want to make this timeout configurable. In which case in your app.config file you would add a section:
<appSettings>
<add key="driver.Timeout" value="20" />
</appSettings>
Then in your code you would do something like:
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(Int32.Parse(ConfigurationManager.AppSettings["driver.Timeout"]));
This way if you deploy your app somewhere and wanted to make the timeout configurable you would just edit your app.config file in a text editor and change the value.

Related

How to chage default directory of .dlls creating after built with runtime and probing?

I want to move all .dlls to "lib" folder after building my application. Default program creates them in directory:
bin\Debug\netcoreapp2.2
And this is directory where I want to place my .dlls:
bin\Debug\netcoreapp2.2\lib
I create script which moves my .dlls to this folder and put it in post-built event. It works correctly.
Next, I add runtime to my app.config file like I saw in many tutorials and articles on stackoverflow.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib"/>
</assemblyBinding>
</runtime>
But, after building and starting my program, console says:
The application to execute does not exist:
app\bin\Debug\netcoreapp2.2\myDLL.dll
I want to know what's wrong with my application? How can I change the directory in which program is looking for .dlls?
I guess what you need is the codebase element in the configuration.
From documentation, If the assembly has a strong name, the codebase setting can be anywhere on the local intranet or the Internet. If the assembly is a private assembly, the codebase setting must be a path relative to the application's directory.
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<codeBase version="2.0.0.0"
href="http://www.litwareinc.com/myAssembly.dll"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Hope this helps.

Starting a barebones MVC C# ASP.NET project in Docker gives "Compilation Error"

To start, if Overflow is not the right Stack site for this, please let me know! Also, if you need to see any other files, please feel free to ask.
I started a sample Visual Studio C#/ASP.NET MVC app to try and put in Docker as a Proof of Concept to see how to configure the two parts to work together. It works locally, but when deployed via Docker it throws an error.
Server Error in '/' Application.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0016: Could not write to output file 'c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\e22c2559\92c7e946\App_Web_index.cshtml.a8d08dba.w8h4d0pg.dll' -- 'The directory name is invalid. '
Source Error:
[No relevant source lines]
My workflow is to publish to the filesystem, then build the docker image via the dockerfile below. I use the option to "precompile" the source (leaving me confused by the error). Below are the files I feel are relevant (comments after hashtags added to this post, not in the actual files).
dockerfile
FROM microsoft/aspnet
COPY ./ /inetpub/wwwroot #this copies from the published folder, which contains 'bin'
web.config
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=301880
-->
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<appSettings>
<add key="webpages:Version" value="3.0.0.0"/>
<add key="webpages:Enabled" value="false"/>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
<httpRuntime targetFramework="4.0"/>
</system.web>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
<bindingRedirect oldVersion="1.0.0.0-5.2.2.0" newVersion="5.2.2.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
I use the following commands to build/run the environment:
docker build -t testapp .
docker run -d --name test -p 20012:20012 testapp
the -p doesn't seem to want to work, I've tried going to that port on the docker's IP and it always gets refused, so I go directly to the docker's IP gotten from an inspect.
Things I've tried to varying levels of failure:
EXPOSE in the dockerfile, never helped or hurt.
CMD/ENTRYPOINT I very well might have been using them wrong, but I read ENTRYPOINT is irrelevant with the microsoft/aspnet base image
ripped out authentication/entity which got me further (I actually just started a new project without them to begin with)
Any help would be appreciated!
Update 1:
After using the answers to solve the issue, it successfully builds and as was my end-goal prints the IP of the server (docker container) to show how the load-balancing/Swarming works. For anybody interested in a pre-built docker image (in a windows container) which prints the IP of the docker image you hit, as a proof of concept for load balancing/Swarming with docker, the image is on hub.docker.com under the image name acmiles/aspnet_printserverip. Feel free to check it out, but it's just a sample project with added logic to print the Docker container's IP on the index page. Below is the final version of my dockerfile used to build the image.
FROM microsoft/aspnet
RUN New-Item c:\testapp -type directory
WORKDIR /testapp
COPY ./outputRelease/ .
RUN Remove-WebSite -Name 'Default Web Site'
RUN New-Website -Name 'webapp' -Port 80 -PhysicalPath 'c:\testapp' -ApplicationPool '.NET v4.5'
I had the same issue when trying to get an existing MVC app working in docker. I went all around the houses trying to resolve the issue and have spent many hours on it over the weekend! I tried setting permissions on various temp folders to various accounts and I tried setting the app pool to run with a local profile.
I finally got it to work by adding the app pool account to the local admins group. This isn't a final solution, but it's got it working and pointed me in the right direction for which account I need to assign permissions for.
Here is my Dockerfile;
FROM microsoft/aspnet
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ARG source
WORKDIR /inetpub/wwwroot
COPY ${source:-obj/Docker/publish} .
RUN Add-LocalGroupMember -Group 'Administrators' -Member 'IIS AppPool\DefaultAppPool'; \
IISRESET;
Hope it helps.
Thanks
Jared
Another workaround is to work on a different website. In my docker file I remove the default website and add a new one.
RUN New-Item c:\webapp -type directory
RUN Remove-WebSite -Name 'Default Web Site'
RUN New-Website -Name 'webapp' -Port 80 -PhysicalPath 'c:\webapp' -ApplicationPool '.NET v4.5'

ASP.NET MVC WebConfig with linked config file causes exception

I have a large ASP.NET MVC project with a data access layer that uses Entity Framework. As well, I have a Windows service project (in a different solution) that makes use of the same DAL project. I have my Web.config/App.config setup so that the connection strings are loaded from a separate connection.config file that is in a shared location. The connection configuration is linked (Add Existing Item > Add As Link) in both projects with Build Action = Content and the Copy To Output Directory = Copy if newer.
The Windows service project runs with no issues, I can see the service connecting to my database correctly. However the ASP.NET MVC project throws an excpetion saying Unable to open configSource file 'connection.config'. (C:\Path\To\My\web.config line 9).
I checked that the connection.config file is copied to output directory. I also tried making a copy of the connection.config file in the ASP.NET project (instead of linking it) and this runs just fine. Why does linking the file suddenly cause an exception?
My files below for reference
App.config (Windows service)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings configSource="connection.config" />
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-8.0.0.0" newVersion="8.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
[...]
<connectionStrings configSource="connection.config" />
[...]
</configuration>
connection.config
<?xml version="1.0"?>
<connectionStrings>
<clear />
<add name="MyConnection" connectionString="Data Source=./localhost;Initial Catalog=MyBatabase;Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
</connectionStrings>
Edit
I came across this answer that works, however I'm concerned how this would affect the application in release mode or when it's deployed. As well I still don't understand why having the file linked has a different behavior than when it's copied in.

How to properly access the PrivateBinPath property of the current AppDomain?

Since AppDomain.AppendPrivatePath() is obsolete, I'm trying to figure out how to specify a PrivateBinPath for the current AppDomain in my project without spinning up a whole new AppDomain, and being able to access it later.
I know I can set the PrivateBinPath on an AppDomainSetup object (which would be ok if I wanted to create a new AppDomain), and I also know that I can add it to my app.config like so:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath=".\AlternateLookupPath" />
</assemblyBinding>
</runtime>
However, when adding this entry to my app.config, the AppDomain.CurrentDomain.SetupInformation.PrivateBinPath property is null.
use
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="AlternateLookupPath" />
</assemblyBinding>
</runtime>
According to http://msdn.microsoft.com/en-us/library/823z9h8w.aspx the privatePath is already interpreted as "subdirectories of the application's base directory"... so I suspect that using .\ is somehow messing things up...
From the docs:
If the directories specified for
PrivateBinPath are not under
ApplicationBase, they are ignored.
So, you need to make sure the paths you are add are under ApplicationBase.
This only works with app.config however. If you need to do this at runtime, use the AssemblyResolve event as described in the docs:
http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx

Binding redirects

Where is the best place to find information on binding redirects? or maybe just a basic explanation of where you put these redirects within a project?
Where you put it can only be configuration. Find details here.
Why not start from the beginning?
after understood what it does, you will end up with something like:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="myAssembly"
publicKeyToken="32ab4ba45e0a69a1"
culture="neutral" />
<bindingRedirect oldVersion="1.0.0.0"
newVersion="2.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
There are several configuration files that can include binding redirects. Another option besides the configuration files is to use the AppDomain.AssemblyResolve event to decide on redirects at run time. I've included some sample code in this answer.

Categories