I'm having trouble figuring out how to do something that I imagine is very common in an ASP.NET Web Forms application.
It's a pretty standard app with the usual inputs (dropdowns, text editors, etc), and we want to make sure that when the user tries an action (like clicking the "save" button after their edits), the data they've entered is not lost if they are logged out without their knowledge (session expired, cache got cleared, etc).
We use Telerik's ASP.NET Web Forms controls, and our first solution was to hijack the OnRequestStart event of the RadAjaxManager, along with several built-in Telerik javascript events (overwrote the Telerik events for button click, drop-down opening, etc) in order to make sure that our authentication check would be hit on just about every action throughout the app. From those functions we then called a synchronous Ajax request to a web method that returns whether the user is currently authenticated. If they aren't, we stop the current request in javascript and pop up a login window so the current page is not redirected.
We did this without the foresight that there would be potentially thousands of requests to this web service, which essentially crashed the app in spectacular fashion. I've been exploring other options, like using the Application_AuthenticateRequest event in the Global.asax, but no luck so far.
The web service solution is kind of ideal in theory, if only it didn't doom the app to a fiery, unresponsive death...! Any thoughts that could point me in the right direction? Thanks in advance for any help.
Related
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.
I have a WPF application that redirects to a payment system and then starts pooling a database to see if the transaction reference was posted back via a different channel.
I had a chat with one of my programmer friends and he said that there was no need for pooling and I could have simply tracked Url to which payment system redirects after successful payment and react accordingly.
Code to open window and redirect agent to payments system is as follows:
var process = Process.Start(new ProcessStartInfo(url));
Is there a way to get the Url of the Browser Window?
I would recommend to use a web browser control inside your application. There are very good ones and a built-in version (called WebBrowser). Process.Start is a problem since you never know which browser (and version) is loaded. You have support a lot of different ways to get the URL.
The benefit of using a web browser control in your application is that you have absolute control of the web browser, you can handle events like loading of pages, which enables you to perform checks on the URL. I use this myself to do OAuth authentication on a client and get the token back from the URL and parse the token out of it.
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.
I've got to write a .net windows forms application that will open a webpage and then be able to react to the user clicking on certain links on the webpage. The specification I've been given has the links on the webpage just being http links.
Is there a way for my .net application to have a minimal web server on it which will allow it to handle http requests on a given port?
Use an HttpListener.
http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx
If all you need is to show a webpage, and you don't have any restrictions on the browser used, then the WebBrowser control will do the trick.
Drag it on to your form
Set the Url property to the page you need to display
Attach to the Navigating event
You can now respond to clicks, cancel them, do whatever you like. If it's just responding to client-side clicks you need, you don't need a web server. If you DO need a webserver, WinForms shouldn't have anything to do with it.
webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
private void webBrowser1_Navigating(object sender,
WebBrowserNavigatingEventArgs e)
{
//Do your thing... maybe set e.Cancel if you don't to navigate
}
Please look at the WebBrowser control and specifically the "ObjectForScripting" property. If you set it to the parent form you can actually handle javascript events from the page loaded in the webbrowser in your c# code!!!
I hope that helps!
There are different ways to do this depending on what functionality you need. If all you need to do is respond to click events, and you don't need "full" http protocol support, you can just open a socket and parse what comes in from the browser.
Alternatively, you can use HttpListener, which takes care of the http protocol parsing for you and is relatively easy to use. For what I think you need, this is probably the preferred approach. Simple, non-compiling example here: https://gist.github.com/1770645.
The "holy grail" is hosting the ASP.NET runtime in your windows forms application. I've done this and it is pretty involved. The runtime has to be hosted in a separate AppDomain, so you end up jumping through a lot of hoops to get everything running and hooked up. It also involves writing an implementation of HttpWorkerRequest that is more full featured that the framework provided SimpleWorkerRequest. Incidentally, this also works for windows services, which gives you a great way to provide service management and monitoring through a browser without having a dependency on IIS.
I have interpreted the question differently to other users, so maybe I am way off but, I read it as he is trying to render web pages from the web and react to a user clicking on a link within the web page.
The only way I can think of doing this is by using some form of renderer ie webkit and hooking into that to intercept the clicks a user makes.
You can use Nancy
Site of project: https://www.codeproject.com/Articles/694907/Embed-a-web-server-in-a-windows-service
My company is developing a Silverlight application which we then give to our clients who integrate it with their product. You can log into the application by going through a form or using a URI where you pass some needed data. If you provide false data (i.e. you can not be authenticated) you get a message and the applications closes. Then the user just has a blank (white) screen in front of him. We don't want that to be the case any more. Instead we would like to redirect to the calling page (where the user clicked the link to start the app).
So if for example user A has his application open on http://hisdomain.com/work and clicks on a link that redirects him to our Silverlight app where the authentication fails we would like to show him a message (this is happening at the momment) and then redirect him back to http://hisdomain.com/work.
Any ideas how to do this?
I am still in R&D about this so I have not much of an idea about it. The only thing that came to my mind was to pass in the calling URL along with the rest of the data.
Thanks.
If you can pass the starting URL into the Silverlight app with the startup params, you can redirect back with this:
System.Windows.HtmlPage.Window.Navigate(new Uri("YourStartupUrl.aspx", UriKind.Relative));