windows form application to web page application - c#

I have this requirement for my project. Already there is an existing windows form application,
Which sends email when a button is clicked. There's a lot of code behind the application.
It validates the field serial number which is a text box by connecting to database.
The validation error pops up as another windows form.
It generates a report form after sending an email. There's a configuration button which is accessible only to particular users which opens configuration form which has details of email settings.
Now All this is developed using windows forms. My new requirement is i need to develop
the same in a ASP.NET web page having similar functionality.
I tried using click once deployment, but that's not they needed. they want it as a webpage.
Is there any tool or way i can show the application in ASP.NET web page?
Do i need to start the coding from scratch?
Thanks in advance

As to what Rex said, you are going to have to start from scratch. The coding behind it is different. Validation and functions work differently in asp.net than they do in .net.

You will have to start from scratch for reasons already mentioned. If this is your first ASP.net application here are a few tips for what you want to do:
1- For validation and transfer to the email report to work in a similar way you can use Response.Redirect or Server.Transfer or JavaScript. All of those methods have pros and cons, see Server.Transfer Vs. Response.Redirect for an example of the first two. For javascript you'll need to write a javascript function in the .aspx file or inject javascript in the page with response.write.
2- If you validate with JavaScript you also need to validate server side to make sure someone doesn't try to pass bad values to you. JavaScript can be disabled and users can call your report page and configuration page directly, while with windows forms you control that flow you don't on webpages.
3- You'll probably have to use CSS to style elements in your email configuration form and in your initial form. Positioning, docking, anchoring and so on is completely different in webpage and done with CSS. Have fun learning the CSS boxing model, what absolute positioning is, and what clear and float do ;)
4- The most important thing is that the Web is stateless. You can't use private members to keep information between page reload on the web. When you pass a value between 2 pages the first one doesn't exist anymore so you can't just do Class.somemembervariable as usual. Check out what viewstate, sessionstate and querystring are. When your page reload, without these, everything is loss. Clicking a server-side button cause the page to reload, which you need to handle (it's called postback). This also implies that when you serve the report page you will have to pass some Id for the email and check the user, so when you call the 2nd page you need to pass to it some id so it can work. I spent more time on this one because it's the most important difference between asp.net and windows form.
5- For restricting access to your email settings page you will probably need to use windows authentification if this is an Intranet site or Forms authentification if this is an Internet site. Check Starting ASP.NET Forms Authentication for some basic overview.
6- ASP.Net has a codebehind file where you write the actual code, and an .aspx page where you put the html tags, javascript, styles, and data binding with <%= %> tags.
7- You will probably have to work with IIS as well to make your website work unless you work at a very formal place where specific peoples take care of that. At the very basic you'll have to create an application pool, make it compatible with 32/64 bits and set up authentification in IIS.

Related

How to ignore duplicate asp.net WebForm page submissions at the server (IIS 7.0)

I maintain a legacy (7yr old) ASP.NET 4.0 WebForm site. Our user base is around 2K-3K concurrent users during peak activity, usually in the spring of each year.
I've been able to trap in the code, a user submitting the same webform more than once to the server...however the user is only clicking the submit button once. I've witnessed the activity to verify single-click submission.
For some odd reason, the browser (chrome) is posting the same web form 2,3, sometimes 4 times to the server. It seems to happen to most everyone using the app and varies from once every 5th button click to as high as every 20th button click. These duplicate submissions happen within milliseconds of one another.
Is there a good way for the server to recognize another request from the user and ignore it? Since it appears the browser is the culprit, the page content for the submission would be identical on subsequent submissions.
fwiw, I'm aware of the anti-forgery methods for crossSiteScripting in MVC, but this app is strictly WebForm (no MVC).
I'm not a heavy web programmer, but can learn just about anything. Most of my time is spent in T-SQL. But such is the way with funding for maintaining older apps. :)
(WebApp/LoadBalancer uses sticky-sessions, with ASP.NET State Server supporting 3 web servers for this app, if it matters. Once a user logs in against a specific web server, all traffic from that user stays on that specific web server.)
edit: i did find this: Generating AntiForgeryToken in WebForms which I think is a good solution...need to absorb it for a bit and see how it works in my prototype project.

People picker control implementation in asp.net mvc application

I want to include the Sharepoint people picker control type in my application, My app is developed in asp.net MVC. is there a way so that i can include the GAL feature in my asp.net application. This should work even if the outlook is not installed in user pc.
Taken from this page dated March 1 2013
"SP controls can only be used on SP hosted pages. Currently the only control designed from the ground up to be consumed on all page types (provider-hosted, auto-hosted or sp hosted) is the chrome control."
and another post from an MSFT
"I've consulted with several colleagues and the consensus seems to be that SharePoint's client side people picker, which is JavaScript, cannot be used in a provider-hosted app. The reason is that there's no way to get a client context on a remote web page. You mention the TokenHelper.cs which is managed code, not JavaScript. I have a question pending with the product team to see if there's anyway to get the context with managed code and pass it to JavaScript. I didn't want you to have to wait any longer for an answer."
I would suggest writing a plugin. (Although I have never had the requirement to implement it YET)
How :
you write a controller that loads users from AD, and then send a JSON object of these to your client via AJAX and then use jquery auto complete to filter names as the user types.
Or
Simulate the "check User " button by making AJAX calls to that controller and check if name exist on click of that button. then write appropriate error messages if false.
I would still be on the lookout for other solutions though

Refresh client browser when adding new line in a specific table

My scenario:
After client login, my user will be redirected to the index.aspx page.
Inside this page I will put one div with a gridview inside.
This gridview will be showing data from one table.
My question is: How to refresh this gridview always that one record is
saved on this table?
Ps.: I´ve seen a lot of examples using "server push" tecnology, comet, ajax, etc.
Don´t know the best way to do that and can´t find a really simple example.
When a new record is added to the table, the real challenge is communicating those changes to the client in real-time without polling in intervals or requiring some sort of user interaction.
You have a couple of options:
Your best bet is to use a WebSocket, which enables bidirectional communication between the client and server. This is the solution I would pick.
Here are some examples using WebSockets:
Building real-time web apps with WebSockets using IIS, ASP.NET and WCF
HTML5 C# WebSockets Server and ASP.NET Client Implementation
C# WebSocket Server
WebSockets in ASP.NET 4.5
WebHooks and WebSockets in ASP.NET
There are a few good libraries around too that will take care of most of the leg work. A couple to check out are WebSync and PokeIn. Both products offer decent documentation and community editions that you can download for free.
Here are some tutorials to check out:
WebSync Tutorials
PokeIn Basic Tutorial / PokeIn Advanced Tutorial
Use AJAX to poll for changes every X number of seconds. If changes are detected reload the page, otherwise do nothing.
You can use setinterval javascript method. I act as a timer and use submit form to refresh the page. other method could be asp.net ajax toolkit timer control here
put your grid inside an update panel and set "Update Mode" to always
You can use Update Panel which uses AJAX under the hood. Refer to this link for a short and simple demo.
You can also use plain old html
<META HTTP-EQUIV="REFRESH"
CONTENT="15;URL=http://www.I18nGuy.com/index.html">

ASP.NET manipulating and fire action on html

I am working on a project in which one functionality is that this page obtains data from other page (not web service) and then displays it on a grid and use hightcharts for charting.
The problem is that this data I want to read is in anotherpage.
I know that I can read html from other pages... but to get this information on the page, I need to fill 2 input text for a filter and press a submit button.. then it displays a table and this is the table where I need to extract the information.
Is there a way to do this automatically on c#?
There are plenty of ways to do this; the most common revolve around AJAX. You can initiate a callback from the client via Javascript to a method on the server, which can update controls in an UpdatePanel, for example.
You can also make client side calls to server side Page Methods. Effectively, this is a static method on your webform that you can call from the client via javascript/jquery and AJAX.
EDIT.
It turns out that you want to scrape another site. The easiest way for you to do this is have a server side page method on your website that does this - it requests the page from the client site, extracts the info you want, and then returns that to your client. Your client can of course call this as a page method.
See https://web.archive.org/web/20210513000146/http://www.4guysfromrolla.com/webtech/070601-1.shtml for a tutorial, and I do suggest using the HTML Agility Pack as that article mentions.
Further EDIT
You want to further manipulate the page on the remote site; if you can't or don't want to speak to the developers of that site to work out a way of doing it programmatically, then you'll have to cheat. Get Firebug and Tamper Data. Use Firebug and Tamper Data to see how clicking the button on the remote site makes a request and posts it to the server - you want to emulate doing the same. If you know what data is being posted then you can, from your server, make exactly the same post.
You often have this kind of problem when trying to scrape AJAX websites.

recommended way to handle this case in .NET for web application

I am relatively new to web development and am trying to figure out what would be the recommended way to deal with my current situation.
All of this needs to be in the .NET framework.This is a very simple use case, but I am required to deal with a bigger problem here.
Here is the flow of things:
Client clicks a button on a page: "Calculate Sum"
This invokes a call to the webservice which calculates the sum and returns some extra info on how to render it on the html page
The client receives this info from the webservice and populates one of the variables in the javascript that is used in the resulting page and the extra info is used to render the html page
The resulting page would have a button; when clicked would redirect to a third party application. It would then process this request and send a POST back to one the URLs I have specified. I am then required to consume the info (string) that they would send back.
Let me know if I am not clear in any of this and if you want me to specify more info. This is more about learning on the job and so I am trying to find out the best way to solve this problem.
Thanks
It sounds like, if as you say everything must be in .NET framework, then you can use Visual Studios to develop this project in VB or C#. Essentially, the page that initially sends the request to the web service would be built as a .aspx webpage. Then you can build a web service in C# or VB .asmx which handles the calculation, returns a result that is parsed by javascript on another asp.net web page and produces a button to send the gathered data as a POST to another URL.

Categories

Resources