ASP.Net Webforms application logging out after visiting Payment Gateway
I am adding some features to an existing webforms application written in c# using .net framework 4.6. After redirecting to an external payment gateway, the site returns but the user ends up being logged out so the transaction does not complete.
The application uses a payment gateway to make credit card payments. Once the process starts, the applications redirects to payment gateway's site for a few seconds then returns to our checkout page. However the user is logged when the page returns. As a result the process does not complete
The session cookie is set to same site lax and secure.
I am using visual studio 2017 and working on my dev machine.The only thing I can think of so far is that session information is cleared whenever my application redirects to the payment gateway. So when it returns the user is no longer logged in. However, I do not know what to do to keep the session logged in.
Any assistance would be appreciated
1 answer
-
answered 2021-01-18 23:34
abujafar
Seeing that I was working in Visual Studio 2017, when I ran the application, I was running with a URL of localhost:port_number e.g.'https://localhost:44390'. However, the url of the live site is something like 'https://www.specific.url.com'.
The actual url was stored in the database and was being retrieved whenever the payment process was executed. This actual url was also being sent to the payment gateway as the return url. Upon return the live url: 'https://www.specific.url.com' did not match the dev url: https://localhost:44390. This somehow caused the session info to be lost.
Once I changed the url in the database to https://localhost:44390, everything started working as expected.
See also questions close to this topic
-
How to generate fake data with pre-defined list for one column while use Bogus to generate random string in another column in C# EF Core?
I have a list of 9 items and I would like to generate exact 9 records in Standard table with the values in the list for StandardName column and use Bogus to generate the random value for the Description column. Is there a quick and easy way to do it with Bogus C#?
var standardNames = new List<string>() { "English Language Arts Standards", "Mathematics Standards", "Fine Arts Standards", "Language Arts Standards", "Mathematics Standards", "Physical Education and Health Standards", "Science Standards", "Social Sciences Standards", "Technology Standards" };
using System.Collections.Generic; namespace EFCore_CodeFirst.Model.School { public class Standard { public Standard() { this.Students = new HashSet<Student>(); this.Teachers = new HashSet<Teacher>(); } public int StandardId { get; set; } public string StandardName { get; set; } public string Description { get; set; } public virtual ICollection<Student> Students { get; set; } public virtual ICollection<Teacher> Teachers { get; set; } } }
-
Deserialize an XML string with WCF
I have a problem with deserialize an XML string into C# objects. The problem is that I the result will always be null. This is my XML string which is stored into a string variable.
<objects> <object> <dateadded>1614924419</dateadded> <id>CF7E7B22-1D3A-4CFE-91F9-F8C5C2DB4069</id> <name>NorthernLights</name> <parentid>ED98C97F-A202-48ED-AEEA-34362508A30B</parentid> <type>file</type> </object> <object> <dateadded>1614924419</dateadded> <id>CF7E7B22-1D3A-4CFE-91F9-F8C5C2DB4070</id> <name>Northern</name> <parentid>ED98C97F-A202-48ED-AEEA-34362508A30C</parentid> <type>file</type> </object> </objects>
Those are the classes that I have created that represent the XML document. I suppose something is wrong there. Can someone help me with this?
// This is the class for the objects tag namespace DataContractSample.DataContract.Model { using System.Collections.Generic; using System.Runtime.Serialization; [DataContract(Name = "objects", Namespace = "", IsReference = false)] [KnownType(typeof(IList<Image>))] public class Images { [DataMember(Name = "object", EmitDefaultValue = false, IsRequired = true)] public IList<Image> ImageList; } } // This is the class for the object tag namespace DataContractSample.DataContract.Model { using System; using System.Runtime.Serialization; [DataContract(Name = "object", Namespace = "")] public class Image { [DataMember(Name = "Id")] public Guid id { get; set; } [DataMember(Name="parentid")] public Guid ParentId { get; set; } [DataMember(Name="name")] public string Name { get; set; } [DataMember(Name = "type")] public string Type { get; set; } [DataMember(Name = "dateadded")] public string DateAdded { get; set; } } }
Thanks!
-
C# Netcore 5.0 with Docker-compose not working on Port 443
I do not understand why port 443 is not mapped and I do not have access via Docker. Docker setting
The log does not say that it is listening on port 443, but why ?
warn: Microsoft.AspNetCore.DataProtection.Repositories.FileSystemXmlRepository[60] Storing keys in a directory '/root/.aspnet/DataProtection-Keys' that may not be persisted outside of the container. Protected data will be unavailable when container is destroyed. warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {53ba37bf-01f4-40be-9aa7-ff497e55a160} may be persisted to storage in unencrypted form. info: Microsoft.Hosting.Lifetime[0] Now listening on: http://[::]:80 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development - ASPNETCORE_URLS=https://+443:;http://+80 - ASPNETCORE_Kestrel__Certificates__Default__Path=/https/XXXXX.pfx - ASPNETCORE_Kestrel__Certificates__Default__Password=XXXXXXXX - ASPNETCORE_HTTPS_PORT=443 info: Microsoft.Hosting.Lifetime[0] Content root path: /app warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3] Failed to determine the https port for redirect.
Thanks for your help and suggestions
-
Merge 2 Datatable using Full Outer Join in C#
I need to merge/join datatables on C# with a common column.
I have checked multiple examples but the expected output is not coming. I have created sample dotnet fiddle for the issue which im facing
https://dotnetfiddle.net/WGDL9R
Below is the example
Table1
Account# | Day01 1234 | 11 4567 | 22 4909 | 33
Table2
Account# | DummyColumn 1234 | 12 1234 | 34 4909 | 99
Table3
Account# | DummyColumn 1234 | 13 7777 | 44
Expected Outcome Merged Table
Table1
Account# | Day01 | Day02 | Day03 1234 | 11 | 12 | 13 1234 | 11 | 34 | 13
Note : Rest column are skipped
I can able to take output as per SQL but im getting data separately in datatables for below query
e.g. Datatable1 = select Code from Employeedetail where Id=79603
Datatable2 = select B.Name from EmployeeFamilyDetails where Employeeid=79603I need to merge all datatables into one with Full Outer Join
Example SQL Query :
select Code,Email,B.Name,C.Name from Employeedetail A Full Outer join EmployeeFamilyDetails B on A.ID = B.Employeeid Full Outer join EmployeeNomineeDetail C on A.ID = C.Employeeid where B.Employeeid=79603 and A.Id=79603 and C.Employeeid=79603
-
C# MVC ASP.net ,facing slowness in loop task after time of starting
when i create any function that have to read from excel and then do some algorism on the data then write the result in the database ,
in the start of excitation the loop is working in very fast time ,but after a while it git slow and slow ,
please i need help .
-
how to get all controls of aspx page without running in browser
I have aspx page which may controls. I want get all controls of aspx page without running into browser. Means by taking physical path, I want to get list of all controls from aspx.
for example - I have following aspx page and I want to get all controls(textbox and label) and their attributes.
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="WebApplication1._Default" %> <asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </asp:Content>
-
Script Bundle and Style Bundle returning 302 Not Found Error
I'm trying to add Script and Style Bundling to a fairly old legacy WebForms application. It works great in debug mode or with BundleTable.EnableOptimizations = false.
But when I try to enable optimizations as it should be in production, it's not actually creating the bundles so they are returning 302 Not Found errors.
Here's my BundleConfig class
public static void RegisterBundles(BundleCollection bundles) { bundles.IgnoreList.Clear(); bundles.Add(new ScriptBundle("~/bundles/js") .Include("~/Scripts/jquery-{version}.js", "~/Scripts/jquery-migrate-{version}.js", "~/Scripts/jquery-validate.js", "~/Scripts/jquery-validate-unobtrusive.js", "~/Scripts/bootstrap.min.js", "~/Scripts/css_browser_selector.js", "~/Scripts/menu.js", "~/Scripts/owl.carousel.js", "~/Scripts/owl.carousel2.thumbs.js", "~/Scripts/general.js")); bundles.Add(new StyleBundle("~/bundles/css") .Include("~/css/bootstrap.css", "~/css/owl.carousel.min.css", "~/css/menu.css", "~/css/style.css", "~/css/responsive.css", "~/css/faeaapps_style.css" )); BundleTable.EnableOptimizations = true; }
Application_Start in Global.asax:
BundleConfig.RegisterBundles(BundleTable.Bundles);
In the of the master page:
<asp:PlaceHolder runat="server"> <%: Scripts.Render("~/bundles/js") %> <%: Styles.Render("~/bundles/css") %> </asp:PlaceHolder>
How they're getting rendered:
<script src="/AppName/bundles/js?v=wMldU3OL4sMBTxZpOsGwPTsnbckw_2T1BVZNp1Lopag1"></script> <link href="/AppName/bundles/css?v=Mdb6m_Rz-GAE4EuPddeqG8CHLfgK1ODoN0WhXZmy09k1" rel="stylesheet"/>
What happens when the browser tries to load them:
Any idea what I'm doing wrong?
-
pdf file not opening on android phone
I am trying to show a pdf file embedded on my web page as soon as the web page loads. This is what I am doing to show the pdf file on my aspx page:
<asp:Literal ID="ltEmbed" runat="server"></asp:Literal>
and in my .cs page
string embed = "<object class=\"ss-pdfjs-viewer\" data=\"{0}\" type=\"application/pdf\" allowfullscreen webkitallowfullscreen>"; embed += "</object>"; string fileName = HttpContext.Current.Session["RequestType"] + "_" + HttpContext.Current.Session["MailID"].ToString() + ".pdf"; ltEmbed.Text = string.Format(embed, ResolveUrl("~/Documents/" + fileName));
everything works fine. I can open this pdf file in my web application, iphone, but not in android phone.
I am not sure why it is not working in android and all other places.
-
Bootsrap, Required, Fontawesome, and ASP.NET webforms
I'm trying to do something which I think should be doable, but I'm having problems with. Here are my requirements:
- I need to check that four values on a webform form are entered.
- I need to allow a user to submit the data on a button click.
- The button has some text and has some fontawesome icons in it.
- When the data is submitted, I need to turn off the button so that the user does not inadvertently click it again and submit the exact same data the second time.
- Get the required popups from bootstrap on an insert/update of data, assuming some data has not been entered.
I am only able to get pieces of this working. Here is what I have tried:
An asp:LinkButton. I can get everything but the bootstrap required popups. I found that this seems to be caused because bootstrap required looks for a button of type "submit".
An asp:Button. I can get everything but the fontawesome icons. I found that I can actually insert this on a jquery document ready method, but I get all kinds of asp .net security violations when I try this. I simply can't open this up.
A button tag with a runat="server" on it. I've tied this in with the asp.net button click event like below. Unfortunately, when I click the button, if there is a client side onclick event handler, the server side click event never gets called. I am able to style the button like a link. This is the option that seems to get me the closest. Unfortunately, I seem to be able to get the client side onclick event or the server side onserverclick event, but not both. I'm open to any and all suggestions here.
<button type="submit" ID="btnSubmission" runat="server" onserverclick="lbCaseUpdate_Click" class="buttonAsLink nav-link pl-0" ><i class="fa fa-pen fa-fw"></i> Update</button>
What I need is a button/link that activates the "required" display in bootstrap, contains the fontawesome icons, runs some client side javascript to somehow communicate an update is occurring, turns off the input button, and then performs the server side operation. I don't see how to get it. I'm open to any and all suggestions.
TIA
-
Spring Boot | Session Replication | Mode COOKIE
I have a spring boot application up and running. We run it using external standalone tomcat behind LB.
Tomcat version - 9
Springboot - 2.3.4.RELEASE
I have tried with below approach but none works.
web.xml
<session-config> <session-timeout>30</session-timeout> <tracking-mode>COOKIE</tracking-mode> </session-config> <display-name>availment</display-name>
application.properties
server.session.tracking-modes=cookie
Javax-servlet
<dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> </dependency>
But none seems to work, user gets logout as soon as request reaches another server where login request did not come.
-
Spring SessionRepositoryFilter request gets redirected after successful login
We are currently integrating spring session to address the issue on HTTP session dependency on servlet container.
Already added or registered the spring session filter in web.xml.
<filter> <filter-name>springSessionRepositoryFilter</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> </filter> <filter-mapping> <filter-name>springSessionRepositoryFilter</filter-name> <url-pattern>/cbs-rs/*</url-pattern> </filter-mapping>
And in the spring configuration, added the DefaultCookieSerializer to change the cookie name from default SESSION to JSESSIONID.
<bean class="org.springframework.session.web.http.DefaultCookieSerializer"> <property name="cookieName" value="JSESSIONID"/> <property name="cookiePath" value="/"/> <property name="domainNamePattern" value="^.+?\.(\w+\.[a-z]+)$"/> </bean>
We are using form-based authentication. After successful login, it was redirected to login page. It did not route to the next REST calls.
During debug, I have noticed that the client cookie sent and registered in the request came from the servlet container. However, since spring session intercepts the request and add their own mechanism to use spring session, updating the cookie name with the latest spring session ID value causes the next REST calls redirected.
Please click here for the debug image
Is this the expected behaviour of spring session? Is there some configuration which need to be setup to resolve this issue?
-
Django set cookie domain to requested domain
Our application creates sub domains for users dynamically and has logins in it.
I am facing an issue for sessions where the cookie is assigned to domain .mywebsite.com instead I want the cookie to be assigned to the requested subdomain like user.mywebsite.com and.
The problem is when I login to 2 subdomains as the cookie is the same, the sessions are invalid for previous one.
Example:
logged in to user.mywebsite.com
logged in to user2.mywebsite.com
navigates to user.mywebsite.com and then session gets invalid because the cookie is assigned to domain .mywebsite.com
Django: 3.1.1
Platform: Ubuntu 20LTS
-
Setters for session scoped bean not working in RestController
I'm trying to get the username from the session scoped bean once the user has logged in using
/users/login
I've
Autowired
a session scoped bean into aRestController
and in one of the endpoints in the rest controller, I'm invoking a setter on the session scoped bean. But the effect of setters is not visible for requests from the same session.The following is my session scoped bean:
import lombok.Getter; import lombok.Setter; import java.io.Serializable; @Getter @Setter public class SessionSpecificUserDetails implements Serializable { private String userName; }
import lombok.Getter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.context.annotation.SessionScope; @Getter @Configuration public class UserSessionDetailsConfiguration { @Bean @SessionScope public SessionSpecificUserDetails sessionSpecificUserDetails() { return new SessionSpecificUserDetails(); } }
The following is the
RestController
import com.course.backend.coursebackend.config.SessionSpecificUserDetails; import com.course.backend.coursebackend.dao.User; import com.course.backend.coursebackend.repository.UserRepository; import com.course.backend.coursebackend.utils.ResponseUtils; import com.course.backend.coursebackend.utils.UserUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.util.ArrayList; import java.util.List; import java.util.Optional; @RestController @RequestMapping("/users") public class UserController { @Autowired UserRepository userRepository; @Autowired SessionSpecificUserDetails sessionSpecificUserDetails; @GetMapping("/getLoggedInUser") public String getLoggedInUser() { return sessionSpecificUserDetails.getUserName(); } @PostMapping("/login") public ResponseUtils.CustomResponse login(@RequestBody User user) { List<User> users = getAllUsers(); Optional<User> optionalUser = users.stream() .filter(currentUser -> currentUser.getUserName().equals(user.getUserName())) .findAny(); if (optionalUser.isEmpty()) { return ResponseUtils.getErrorResponse(List.of("Username not found!")); } if (optionalUser.get().getPassword().equals(user.getPassword())) { sessionSpecificUserDetails.setUserName(user.getUserName()); return ResponseUtils.getSuccessResponse("Login Successful!"); } return ResponseUtils.getErrorResponse(List.of("Login failed due to wrong password!")); } }
I see that spring is creating proxy for the session scoped bean. (And may be because of that my setters are not having any effect even for the same session?)
My question is what's the correct way to use the session scoped beans in the
RestController
? And what's the good way to get the username for the same session across requests? I tried markingUserController
also as@SessionScope
but that's also not working. -
What is the relationship between IIS Express and maintaining Session State?
I have an application that I recently upgraded to .NET 4.8. When I try to debug the application in Visual Studio, I now get this error:
System.Web.HttpException: 'Session state can only be used when enableSessionState is set to true, either in a configuration file or in the Page directive. Please also make sure that System.Web.SessionStateModule or a custom session state module is included in the <configuration>\ <system.web>\<httpModules> section in the application configuration.'
These suggested fixes already exist in my web.config file.
The very same application code when deployed to my local IIS and to my test server works just fine. The only difference that I can determine is that my development/local/test environments rely on IIS Express/IIS/IIS respectively.
Does this logic make sense? If so, what is the relationship between IIS Express and Session State? How can I investiage/modify settings related specifically to how IIS Express maintains Session State?
-
ServiceStack - System.Web.HttpContext.Current.Session is null
I have legacy .net mvc application integrated with ServiceStack APIs, I need to get/set Session values from ServiceStack APIs in order to communicate with legacy system to ensure proper working. I explored multiple option available in ServiceStack doc/other material but looks like nothing is working in my case.
enabled session feature:
Plugins.Add(new SessionFeature());
tried to use direct:
HttpContext.Current.Session
alternate way:
var req = (HttpRequest)base.RequestContext.Get<IHttpRequest>().OriginalRequest; var session = req.RequestContext.HttpContext.Session;
but none of them seems working.