Dear developer friends,
I have developed a self-hosted API in ASP.Net MVC4 (e.g. http://blogs.msdn.com/b/henrikn/archive/2012/03/01/file-upload-and-asp-net-web-api.aspx), because I needed a solution where I could upload super large files. This works smoothly.
Now I want to upload files to my newly written API through the Bluimp JQuery Upload component.
This works fine, except for some small flaws:
- the progress-bar is not showing
- JQuery raises an error: Unsafe JavaScript attempt to access frame with URL...
It seems clear that this error is raised, because my API runs on another port than the web application, and ajax calls cannot be made over cross domains / ports.
I have already added the forceIframeTransport: true parameter to the fileupload component call. This does some good - without it I cannot upload files at all (because the component tries to upload with an ajax call).
So.. I figured that if there's some way to run my self hosted API on the same port as my web-application (with explicitly defined routes), my world will be happy and shiny again. However.. I'm not quite sure whether this is possible at all..
Unfortunately a proxy from my ASP.Net application will not help me here, as I wrote the API to avoid the IIS limitations (regarding maximum upload size). Using my self hosted API as proxy might to the job, but I think this is a bit.. overkill?
Anyone? Thanks in advance!
Yahoo! Solved it!
var config = new HttpSelfHostConfiguration("http://localhost:49302/api");
In other words - the web api ONLY works when the url starts with /api. All other requests are picked up by my MVC4 web application. But they run on the same port.
So to answer my question: yes it's possible. Just add a root directory.
Related
I am trying to put together a winform app that also has a web interface that can interact with events generated from within the winform portion of the app. I am successfully running the cassinidev server from within the app and asp.net pages are being processed but I am still running into a few obstacles and I am not sure if they are even possible???
I am unable to use code behind pages. I have added the appropriate
attributes to the page directive but I still cannot access controls
from the aspx page.
I am unable to access classes from the web portion of the app. See
screenshot...
Maybe what I am trying to accomplish is not even possible but if anyone can help to point me in the right direction I would be most grateful!
I'm pretty sure you can't do that since the only thing you have available is the "website path" option.
You do however have the source and if you find some way of sharing data (maybe using the ApplicationPool) you could probably do that...but i'm guessing you'd still need to cast that data on startup to a static variable in your website.
Seems like too much work 2 me.
I'd suggest selfhosting WebApi as well and then just using that as the data layer of your website.
Both can be hosted in winforms and webapi CAN share static data directly from your code :)
I am using ASP.NET as the backend for windows phone browser. Sometime I need to make changes on the ASP.NET Pages WHILE users are surfing the website. I want to know how can I provide un-interrupted service to user in such a way they can surf during ASP.NET DLL uploading process:
Assume
say, there are a few ASP.NET (DLL) in production WebServer in such a way that all aspx pages in the one Folder and all DLL(s) in bin-folder.
page(1).aspx , page(1.2).aspx , page(1.n).aspx from DLL(1) and page(2.1).aspx, page(2.2) from DLL(2)
default.aspx from DLL(1)
Question
What will happen if I upload the updated DLL(2) to the production server and leave DLL(1) as it is :
Can user call the deafult.aspx?
Will user still be able to call aspx pages from DLL(1) during the uploading process?
I am a big fan of Martin Fowler's Blue Green Deployment methodology (link).
The idea is simple, have two very similar environments setup (staging & production). You make changes to your code, deploy it on staging, do your testing and then swap staging with production via a simple router configuration.
It has worked great for us so far.
The answer to both the questions is YES
You need Microsoft Web Deployment Tool. Please find more details on below link
How to deploy an ASP.NET Application with zero downtime
Are you hosting within a clustered server environment? If your not, I would be more concerned about a single point of failure rather than interrupting clients briefly during a release.
That said, the update process in such an environment is much better if your fearful of disturbing your users.
I realise that this is going to be a fairly niche requirement and will almost certainly raise a few "WTF's" but here goes...
Within an ASP.NET Webforms application I need to serve static content from a local client machine in order to reduce up-front bandwidth requirements as much as possible (Security policy has disabled all Browser caching). The idea is to serve CSS, images and JavaScript files from a location on the local file system referenced by filesystem links from within the Web application (Yes, I know, WTF's galore but that's how it is). The application itself will effectively be an Intranet app that's hosted externally from a client but restricted by IP range along with standard username/password security. So it's pretty much a hybrid Internet/Intranet application but we can easily roll out packages of files to client machines. I am not suggesting that we expect nor require public clients to download packages of files. We have control to an extent over the client machines in terms of the local filesystem and so on but we cannot change the caching policy.
We're using UpdatePanel controls to perform partial page updates which obviously means that we need to Microsoft AJAX JavaScript files. Presently these are being served (as standard) by a standard resource handler within IIS/ASP.NET. Ideally I would like to be able to take these JS files and reference them statically from a client machine, and no longer serve them via an AXD.
My questions are:Is this possible?If it is possible, how do we go about doing so?
In order to attempt to pre-empt some WTF's the requirement stems from attempting to service a requirement with as little time and effort as possible whilst a more suitable solution is developed. I'm aware that we can lighten the load, we can switch to jQuery AJAX updates, we can rewrite the front-end in MVC etc. but my question is related to what we can quickly deploy with our existing application architecture.
Many thanks in advance :)
Lorna,
maybe your security team is going crazy. What is the difference between serving a dynamic HTML generated by the server and a dynamic JS generated by the server?
It does not make any sense. You should try talking them out of it.
what is the average size of pages and viewstate data. you might need to store viewstate in sqlserver rather than sending it to client browser every time.
We have a web application that uses AJAX to talk to an ASP.NET web service. We would like to write another version that can be used offline. We need to be able to re-use our existing code as much as possible. What approaches should we consider?
The app is currently using XmlHttpRequest to get dynamic data from the server. Obviously the offline version will not be able to talk to the server, but it does need to talk to something! I'm sure installing IIS or Cassini on the client would work, but I was hoping for a simpler solution. Is there no other way for JavaScript to talk to some external code?
There are plenty offline web apps nowaday. It simply evolve from AJAX.
For example:
WoaS (wiki on a stick / stickwiki), Tiddly Wiki,
Google doc and Gmail is going to be offline.
You don't need a webserver to run these webapps in offline mode. Just store the required data, scripts on the client side (usually as XML).
One of the possibilities would be to use Cassini. This is a web server that acts as a host for the ASP.Net runtime. You can host Cassini in a Windows application or a Windows Service. In this scenario you do not have to rewrite the web app and the web service.
Most other solutions do require a rewrite of both your web app and your web service. Depending on the way you have written the existing app you can reuse more or less code.
Have you considered HTML5 with application cache and offline storage?
If you hope to create an "offline" version of your package your biggest issue by far will be the need to install your site into a local copy of IIS (registering a virtual directory, etc.). I pursued this briefly a few years ago and gave up in frustration. It can be done: a number of software vendors such as DevExpress do this so you have local copies of their demonstration projects. Indeed, I was able to do this. The problem was the classic "it works on my computer" syndrome. There was simply no way to guarantee that most of my end-users had anywhere near the technical proficiency to make this work.
Thus, I would strongly recommend that you not pursue this path unless you have very technically proficient users and a huge support staff.
But there is one more very important question: did you abstract all data access code to a DAL? If not, then you have a lot of work to do in managing data access as well.
Update: user "Rine" has recommended Cassini. I just wanted to let you know that I pursued Cassini and another 3rd-party web server as well. I think that there are licensing issues with Cassini but may be wrong - it has been awhile. However, I do distinctly remember running into barrier after barrier with this approach and very little documentation to help me out.
if you want a web application run offline, you need a webserver (IIS for ASP) bound to the localhost (127.0.0.1) address. After this so can access your web application by typing http://127.0.0.1/ in your web browser the same way as you do online.
If your AJAX relies on XMLHttpRequest's, you can:
Make the static versions of XML's you get over XMLHttpRequest and put then into a folder on disk.
Rewrite your XMLHttpRequest URL's so that they point to files on disk.
Rewrite your XMLHttpRequest's so that they don't check status (it's always 0 for the file:// protocol.
All JScript works on file:// pages as well as on http:// ones.
Of course it's not the best way to develop static pages, but it may save you some time on rewriting.
I havent come across any framework specifically built for asp.net like the ones available for PHP or RoR.
Here is a good article by Steven to get you started with HTML 5 and ASP.Net Creating HTML 5 Offline application
Obviously the offline version will not be able to talk to the server, but it does need to talk to something!
Enter HTML5 LocalStorage. It works like a database and enables you to put data on your client. Indeed you have to rework parts of your code in javascript and transmit it to the client, but then it would work offline.
Local Storage works like this:
- Setter: window.localStorage.setItem(KEY, VALUE)
- Getter: window.localStorage.getItem(KEY)
- Remove: window.localStorage.removeItem(KEY)
To get the main page working offline you need to create a manifest. This is used to store complete sites on the client. Please refer to this for more information about manifests:
http://diveintohtml5.info/offline.html
You want to build a web application to work offline?? It can't be done.
You could split the interface code from the rest (in diferent dlls) and create a windows application to mimic the behaviour of your web application. This way you have 2 distinct user interfaces but the same code for business rules and data access.
I don't really see any other way...
I have a problem where a Web Application needs to (after interaction from the user via Javascript)
1) open a Windows Forms Application
2) send a parameter to the app (e.g. an ID)
Correspondingly, the Windows Forms Application should be able to
1) send parameters back to the Web Application (updating the URL is ok)
2) open the Web App in a new brower, if it does not exist
If many browser windows are open it's important that the correct one is updated.
Windows Forms Application is in ASP.NET
Browser is IE6+
The applications are controlled and internal for a specific organisation so it's not a question of launching a custom app.
Question A) Is this possible?
Question B) How do I send parameters to an open Windows Forms Application from a Web App?
Question C) If updating the Web App, how do I make sure the right browser is targeted?
What you're asking for is possible but seems awkward.
Trying to call an application from a web page is not something you could do due to security considerations. You could however make a desktop application which would be associated with a certain type of files and then use content-type on the web page to make sure that your app is called when a URL with this type is opened. It would be similar to the way MS Office handles .doc or .xls documents or the Media Player opens the .mp3 or .wmv files.
The second part (opening a particular web page from your application) is easier.
As you should know the address of your web page create a URL string with the parameters you want and open it in default browser (there are plenty of examples on how to do that, a sample is below).
System.Diagnostics.Process.Start("http://example.com?key=value");
If you want to update the page in the already opened browser or use a browser of your choice (i.e. always IE6 instead of Opera or Chrome) then you'll have to do some homework but it's still quite easy.
PokeIn library connects you desktop application to your web application in real time/per user. Moreover, due to its reverse ajax state management, you could consider both of your applications as one.
Check out
http://msdn.microsoft.com/en-us/library/8c6yea83(VS.85).aspx
Using VBScript in your Web Page you can call an open Windows Forms application and send keys to it.
This only works on IE though and you need to adjust the security settings to allow ActiveX.
Have a look into "registered protocols" (for example here and here). I know Skype does this to make outward phone calls from a web page. But probably some changes will be needed in the win application to intercept the parameters from the url.
I haven't tried this but it should be possible
No I don't think it's possible.
Think of viruses/trojans/spyware. If it were possible to launch an application from a mere HTML page, it would be very easy to install malware.
Browsers are designed to prevent you from doing that.
You could use clickonce to deploy and start the forms app - this should take care of sending the parameter to the app.
While this may not perfectly fit with your application, what about using a web service and the form?
Also, you can pass parameters to ensure IE6, not Firefox opens.
System.Diagnostics.Process.Start("c:\ie6\ie6.exe http://www.example.com/mypage");
Ok, so I actually found a clue to the web -> winform part.
The following code was handed to me from an web application that sends a parameter to a winform app. I assume this solution has some security factors in play (such as allowing running VBScript (and ActiveX?) in the webpage. That's ok for me though.
The code:
<script type="text/vbscript" language="vbscript">
<!--
Function OpenWinformApp(chSocialSecurityNumber)
Dim oWinformAppWebStart
Set oWinformAppWebStart = CreateObject("WinformAppWebStart.CWinformAppWebStart")
oWinformAppWebStart.OpenPersonForm CStr(chSocialSecurityNumber)
End Function
-->
</script>