How to pass EF6 Entity to new page on different server - c#

I am working on a web app (using webForms not mvc) that takes user input and adds it to a database table. This app will be available to users in a dev, qa, and production environment hitting each environments own database.
Currently, I have a promote button that works by connecting to the QA database from Dev or the Prod database from QA inserting/updating the data there and then redirecting to the QA/Prod version of the app.
Instead of doing it this way I would like to save myEntity in a variable and send it with the redirect. I'm thinking something like this:
MyEntityType myEntity = UserInputData();
Response.Redirect("myQAurl", myEntity);
Then in my QA Page_Load have something like:
If( fromDev ){
loadPageWithMyEntity();
}
By doing it this way I hope to prevent QA/Prod database connections directly from dev --> QA or QA --> Prod.
If passing an Entity wont work I could also use an array, list, etc.

When doing a redirect:
Response.Redirect("myQAurl", myEntity);
The way that works is that the server basically tells the browser to make a GET request to the supplied URL. Which means that any information sent over that redirect has to be in the query string on that URL. So you would have two options:
Include a bunch of key/value pairs in the query string which can be used to re-construct the entity on the other end.
Serialize the entity to a string and have one key/value pair with that as the value, then de-serialize to the entity on the other end.
If the entity is large, this could be problematic. There's a reasonable limit to the size of a URL in most web servers.
For large entities, to truly transfer from one system to another where they don't share any back end you would likely need a POST request. Which can't be done with a redirect. Instead, you would show the user a form (which could be entirely hidden and invisible, so not necessarily shown) and the user would have to post that form (which could be done with JavaScript, so not necessarily the user posting it).
Beyond those, you're likely looking at a back-end hand-off, such as storing the data in a temporary database location on one system and consuming it on the other.

Related

How to stop Structure Map from returning the incorrect object from session?

Some of the time Structure Map seems to be returning the incorrect object, this seems to happen when the given web server hosting our web app is under heavy load. The object in question is our own class containing properties for Server and Database name that is used to build a connection string.
Our web application has 2 parts, an ASPX web forms section that heavily uses session and a new part that is in MVC that lives within an area of the web forms project. Both of these areas share the same session. The database connection information is built at login and is stored in session. The web forms area directly gets the database information from session and this is working perfectly fine.
Dim dbInfo as DbInfo = me.Session("dbInfo")
The MVC area gets the database information inject via structure map which in turn gets the object from session.
Public Class WebRegistry
Inherits Registry
Public Sub New()
[For](Of IDbInfo)().HybridHttpOrThreadLocalScoped().Use(Function() GetDatabaseInfoFromSession())
End Sub
<CLSCompliant(False)>
Public Shared Function GetDatabaseInfoFromSession() As IDbInfo
If HttpContext.Current.Session("dbInfo") IsNot Nothing Then
Return HttpContext.Current.Session("dbInfo")
End If
Return Nothing
End Function
End Class
As you can see in the code above that both are accessing the same variable in session and seem to be returning the same value most of the time. But there seems to be some caching happening as the issue is that the old code is using the correct connection (the one that user has logged on with) and the structure map method seems to be caching another database connection.
The way we similated the same behaviour is manaully instantiating the dbInfo in the function GetDatabaseInfoFromSession to another database.
Note that this code has been in production for over a year and we have previous versions of the code on the same web servers working perfectly fine. The latest version of the website started exhibiting this bizarre caching behaviour last week. Notable things that have changed recently are:
The application pool running the site is now 64bit
There have been new kemp load balancers put in place.
Things we already have looked at:
What is the difference between HybridHttpOrThreadLocalScoped & HttpContextScoped (we aren't doing anything with thread so we think this is fine)
Difference between Session and HttpContext.Current.Session (we have the null check in the GetDatabaseInfoFromSession and our old code is not throwing HttpException)
Does structure map start caching at a machine level if it is under load with 64bit enabled or does structure map get confused with active sessions?

Trying to swap my old domain for my new one

I purchased the "real" domain name for my website and I'd like to re-direct all traffic that was going to the old site, to the new site.
Here's the scenario: I currently have http://www.wrestlestats.com, but I want to start having everyone use http://www.wrestlestat.com (note without the "s" on the end).
All of google (and I'm assuming all other search engines) return my results for the old site (with the "s").
From what I've read here, everything is just telling me to put a 301 re-direct either on the page (html meta), or in a web.config, or in the Page_Load code in the controller.
My problem is, these are assuming the old "code" is completely separate and sitting on a different server. No, I have 2 domains pointed to the same site/code. If I place the re-direct in the html meta section, then my page will just keep looping. I'm running ASP.NET Core so I don't have a web.config.
What to do for people running ASP.NET Core?
Just do it in 2 steps ---
Configure new domain (instead of old one)to your site.
Use Forward Domain from your domain control panel with the option of path forwarding.
Forward:-
http:-//www.wrestlestats.com > http:-//www.wrestlestat.com

CRM 2013 Get CRM URL via Custom Workflow

I have a requirement for getting a CRM URL via a custom workflow to use in the next step which is to send an email. The reason for this is to differentiate to users which server this email has come from (UAT/Live).
I have been trying to use HTTPContext route as advised from this site https://social.microsoft.com/Forums/en-US/31ff567d-65ea-4385-a764-68a2121ae8c0/ms-crm-2011-get-path-of-crm-server-url-in-plugin?forum=crmdevelopment but the result I get back is useless as I am I am only receiving an "/" back.
Does anyone know what to do from this point or why this may not be working?
This can't be accomplished, in a supported manner, without creating a connection to the CRM Discovery Service, which requires that you supply credentials. The organization service, available in the workflow does not have a method for discovering the organization's URL.
You have two options:
1) Pass it to the workflow as a parameter using the InputParameter code attribute on your CodeActivity.
2) Create (if you don't already have one) a configuration entity to store the URL and retrieve it in your code.
If you don't really need the URL (i.e., you are not creating a link) then you could just query the Organization entity for the Name attribute. That will give you the Organization's name - which would be the only unique part of the URL. This would allow you to indicate to the user if the Email was coming from UAT or Prod.
I ended up coming up with a solution by using the environment.machinename to pull through the server name. From there i could determine which production server the workflow had been run through and passed a string containing, dev, uat or live to the output to use in my activity emails.
Be aware i had to register the workflow without it being in sandbox mode. Hope this helps somebody in the future.
This was an extremely old question but I came across it while attempting to do something similar.
I found that there is a RetrieveCurrentOrganizationRequest request which was introduced in v9. This will work in sandboxed plugins.
You can use this to retrieve the endpoint urls like so
var currentOrg = base.OrgService.Execute(
new RetrieveCurrentOrganizationRequest()
) as RetrieveCurrentOrganizationResponse;
var url = currentOrg.Detail.Endpoints
.Where(e => e.Key == EndpointType.WebApplication)
.FirstOrDefault()
.Value;
More information here: RetrieveCurrentOrganizationRequest
When I used it, I found that there are 3 available URLs in the Endpoints collection:
Web Application
Organization Data Service
Organization Service
Relevant to CRM 2013 (which the OP was using at the time), there is also the RetrieveOrganizationRequest class which does the same as above; however you have to specify the Organization (and some other information)

Creating View and Controller

Moving at snail's pace I started creating sample MVC app for printing website like vistaprint. I created a database with three tables, Client, JobType, Job.
Client table has ClientId, Name, Address
JobType is a look up table with types LetterPrint, CardPrint.
Job has clientId and jobtype id and fileformat.
Then created a EDMX file with all the table.
Now trying to create controller. How many controller do I need assuming that I will need to create a Client, and a Job. Job Type table will be updated using sql script?
I guess 1 controller for Client and Job each .
How many views I will need?
I think 3 for each of client and job. List, Create(update), Delete(readonly mode).
Am I going in right direction?
Thanks in advance.
In suggestion that there be a some person (administrator or someone) who will create clients and create jobs asked by client I'll build such views:
Jobs:
List of jobs. Can be filtered to show jobs asked by one client. One view, filtering happens in model/controller. There must be additional usually empty string about criteria of filtering. Of course, paging and another features should be enabled.
Create job. Client id can be setuped before rendering view (when it was linked from some client). If not setuped, we must provide autocomplete search by client names. How it looks: admin types client name and in down, in some div with ajax list of clients loaded. So there must be one another action that returns filtered list of clients in JSON.
Edit job
Remove job.
Clients:
List of clients. Paging, sorting, filtering. At each client must be link to jobs asked by client and link to create new job;
Create client
Edit client
Remove client.
If client can login and ask for creating new job, there are must be additional views:
Register page
Login page
After login client must see only his jobs and their status and perhaps dunno about possibility (and have no such possibility) to reset filter. Perhaps, there can be special view for that, but I guess that there is need only in different filter setting in index action of jobs controller.
Special administrative actions must be marked with AuthorizeAttribute. Of course, there are a lot of possibilities to done it, but I think that this is nicest. Questions?

what are the options other than query string to pass large amount of data between pages situated at different servers

One of my client has two servers. One is asp.net enabled while other server is just static.
On the static servers there are just html files.
Now the client want to have a page for maling on static server.
since there is no server side script available on static server I created a page in html which on submission uses javascript to create a querystring with the fields submitted.
this querystring is passed to the aspx page situated on different server where user is asked for username and password.
Everything is going fine but when the data is large then the querystring get ignored. Since there is no upperlimit for the data that a user can submit in one go , 90% of the times i get an error.
I have included the following line in web.config but got no success.
<httpRuntime maxRequestLength="32768" executionTimeout="32768"/>
Are there any other way to pass data over servers??
Post data via request url is a good option, here is an example
http://andreaazzola.com/post/post-data-js
You can send a post request instead, and post your data in a form field.

Categories