I have developed a desktop application which I published using Click Once, my intention is to be able to call up the application in my web application. But this is giving me the following error.
Please, I need help.
This is my Controller Code
public FilePathResult GetFile(string fileName= "TestingApplication.application")
{
var dir = Server.MapPath("~/Common/TestingApp/");
var path = Path.Combine(dir, fileName);
return File(path, GetMimeType(Path.GetExtension(fileName)));
}
private string GetMimeType(string extension)
{
if (extension == ".application" || extension == ".manifest")
return "application/x-ms-application";
else if (extension == ".deploy")
return "application/octet-stream";
else
return "application/x-msdownload";
}
Cannot download the application. The application is missing required files. Contact application vendor for assistance.
Thanks
I later got it working after days of sleepless night. The first thing i did was to delete the content cache on C:\users\username\AppData\Local\Apps\2.0\. And I did rewrite the code to this.
` public ActionResult Download()
{
string path = #"~/Common/TestingApp/TestingApplication.application";
return new RedirectResult(path);
}`
Related
I'll start by saying i'm a C# MVC newbie, but I've set up a site with Identity Management and extended the database with some custom tables to store additional info about my users, so I'm not a total neophyte. I've been working on a VB WPF application that I want to deploy from my new website and that is where I'm running into an issue.
I've created a new controller (User) and a couple of views (Download) & (Setup). I created a downloadmodel used by the download view.
In abstract what I am doing is displaying the download view (get) which has three checkboxes to confirm the user has read the Overview, Installation, and Terms of Service. These are boolean values in the model. I also have a string response message in the model, that displays just above the submit button. Here is the model:
public class DownloadModel
{
public bool Overview { get; set; }
public bool Installation { get; set; }
public bool TermsOfService { get; set; }
public string Response { get; set; }
public DownloadModel()
{
Overview = false;
Installation = false;
TermsOfService = false;
Response = "After checking boxes click the button to begin installation";
}
}
My User Controller handles the Get to initially display the download view, and then in the Post it checks to see if all the checkboxes were ticked, if not it updates the response message and returns the view.
If the checkboxes are all checked then it pulls the subscriber (which must exist because it was created when the user verified their e-mail via the account controller - identity management), then proceeds to update the subscriber with the original (if new) or last download date(s). At this point I want to begin downloading the clickonce setup.exe file, before returning the setup view.
[Authorize]
public class UserController : Controller
{
// GET: User/Download
public ActionResult Download()
{
return View(new DownloadModel { });
}
// Post: User/Download
[HttpPost]
public ActionResult Download(DownloadModel downloadcheck)
{
if (!ModelState.IsValid)
{
return View(downloadcheck);
}
//check to see if all the boxes were checked
if (downloadcheck.Overview == true &
downloadcheck.Installation == true &
downloadcheck.TermsOfService == true)
{
//yes - so let's proceed
//first step is to get the subscriber
Subscriber tSubscriber = new Subscriber();
tSubscriber.Email = User.Identity.Name;
bool okLoad = tSubscriber.LoadByEmail();
if (okLoad == false)
{
//we have a real problem. a user has logged in but they are not yet
//a valid subscriber?
throw new Exception("Subscriber not found");
}
// update subscriber with download in process...
if (tSubscriber.OriginalDownload == DateTime.MinValue)
{
tSubscriber.OriginalDownload = DateTime.Now;
tSubscriber.LastDownload = tSubscriber.OriginalDownload;
}
else
{
tSubscriber.LastDownload = DateTime.Now;
}
if (tSubscriber.UpdateDownloaded() == false)
{
//update of download dates failed
//another problem that shouldnt occur.
downloadcheck.Response = "A problem occured downloading your setup."
+ "Try again. If this error continues please contact support.";
return View(downloadcheck);
}
//download dates have been updated for the subscriber so let's start the download!
//THIS IS WHERE I NEED TO BEGIN THE DOWNLOAD
return View("Setup");
}
else
{
// all boxes were not checked - update message
downloadcheck.Response = "Please confirm you have reviewed the above information "
+ "by checking all of the boxes before clicking on the button.";
return View(downloadcheck);
}
}
}
The download view is pretty straight forward, and the setup view simply confirms the download was started and provides a link to the help-setup page.
I'm really a bit lost here. I thought I'd plug in a return new filepathresponse, but I can't do that and return the setup view.
My other thought was to somehow trigger the download of my /xxx/setup.exe from within the setup view as it is returned - but I'm at a loss as to how to accomplish this.
I'll be the first to admit that my mvc c# code is probably overly verbose and my approach to how I've done this may be totally wrong, but I'm just scrambling to get this done so I can deploy my WPF app to select Beta users for testing. It's been a long time living off savings and I can smell go-live from here.
One final note, I'm using setup.exe clickonce deployment of my wpf app for simplicity, as there are .net and localsqldb prerequisites, but I will not be using automated updates - not that this is really relevant.
Appreciate all input and advice.
After more digging and hacking I've found a solution that works. Firstly in my setup view (confirmation page) I added a simple script to initiate a new function in my user controller:
<script type="text/javascript">
window.location.href = "/user/sendfile/"
</script>
The controller change was simple too. For testing I just used a txt file.
// User/SendFile
public ActionResult SendFile()
{
string path = #"~/xxxx/anyfile.txt";
string content = "application/txt";
//string content = "application/x-ms-application";
return new FilePathResult(path, content)
{
FileDownloadName = "mynewtext.txt"
};
}
What is really interesting about this solution is that the FileDownloadName is what the file content is downloaded as. So in this way I can refer to the actual setup.exe file in the path, but then name the downloaded exe anything I want. Bonus :)
I have a very simple file upload method on my MVC controller which works very well when uploading images from the browsers on my PC.
Uploading Code :
[HttpPost]
public ActionResult FileUpload(HttpPostedFileBase file, string encodedId)
However, if I try to upload an image from my iPhone I get error as
No route in the route table matches the supplied values
I tried removing the parameters from the method and instead accessing the data from the Request object:
Modified Code :
[HttpPost]
public ActionResult FileUpload()
{
var file = HttpContext.Request.Files[0];
string encodedId = HttpContext.Request.Form["EncodedId"];
This results in the same error.
I cant't ascertain what the iPhone is sending to the server as I don't have any kind of development tools on my iPhone.
I name my File which i am sending as File and get it via following code.
[HttpPost]
[Route("UploadAttachment")]
public IHttpActionResult UploadAttachment()
{
try
{
HttpPostedFile File = HttpContext.Current.Request.Files.Count > 0 ?
HttpContext.Current.Request.Files.Get("File") : null;
if (File != null)
{
Uploader uploader = new Uploader();
var Result = uploader.uploadToServer(File);
return Ok(Result);
}
else
{
return BadRequest("File is Required");
}
}
catch (Exception ex)
{
return InternalServerError(ex);
}
}
I have the Download that simply serves a static zip file from the local file system that works in Chrome and Firefox, but not in IE8.
The website is running on localhost with SSL, but I am getting the following error message in IE.
Unable to download Download/ from localhost.
Unable to open this Internet site. The requested site is either
unavailable or cannot be found. Please try again later.
public ActionResult Download(long batchID)
{
var batchFilePath = string.Format(BatchOrderReportsFolder + "\\Batch-{0}\\Batch-{0}.zip", batchID);
if (!System.IO.File.Exists(batchFilePath)) {
return RedirectToAction("Index", "Error");
}
return File(batchFilePath, "application/zip", Path.GetFileName(batchFilePath));
}
Here's what ultimately worked for me. In my case, there was a global ActionFilter on OnActionExecuted that was setting cache-control to "no-cache".
protected override void OnActionExecuted(ActionExecutedContext filterContext)
{
base.OnActionExecuted(filterContext);
var browserInfo = Request.Browser.Browser;
if (filterContext.Result is FileResult) {
filterContext.HttpContext.Response.CacheControl = browserInfo == "IE" ? "private" : "no-cache";
}
}
The information in the following question should help you...
Struts application - unable to download file through https on IE
I have a web page in my asp.net mvc website where user uploads the file. Now my problem is, i need to show the link in a page on click of which user will be able to view the file.
User can upload file or types doc,docx and pdf.
How can i do this.
Please help,
Thank's
The most simple thing you can do is to use System.IO.Directory.GetFiles(..), like this:
var myModel = new myModel {
Files = Directory.GetFiles(#"c:\temp")
}
However, Directory.GetFiles(..) will give you an array of strings, which may a bit hard to work with. If you need to use the files in a bit more object oriented manner, refer to the DirectoryInfo and FileInfo classes.
Example:
var directory = new DirectoryInfo(#"c:\temp");
foreach (FileInfo fi in directory.GetFiles()) {
Console.WriteLine(#"FileName: {0}", fi.Name);
}
MSDN reference: http://msdn.microsoft.com/en-us/library/07wt70x2.aspx
Thank's for the reply.
But i have been looking for something like this, which solved my problem.
[HttpGet]
public ActionResult Index(string id)
{
string extension = id.Substring(id.IndexOf(".") + 1);
string contentType = string.Empty;
if (extension == "doc" || extension == "docx")
{
contentType = "application/msword";
}
else if (extension == "pdf")
{
contentType = "application/pdf";
}
if (string.IsNullOrEmpty(contentType))
{
throw new Exception("Invalid file");
}
return File(Server.MapPath("~/Docs/" + id), contentType);
}
Where id parameter in above code is the filename.
Thank's
If you're asking how to avoid your download links from being intercepted by MVC routing have a look at http://weblogs.asp.net/pjohnson/archive/2010/11/11/mvc-s-ignoreroute-syntax.aspx
Our organization has a central solution for forms authentication. I am trying to implement an ASP.Net MVC app that uses this external URL - and it worked till RC! was released...
Here's what's happening
In an ActionAttribute Extension
I check for s session var
if not found
check for a request data chuck
if found, set the session var
if not found - redirect to external URL
if found
continue.
The trouble is that till I updated to RC1, this worked. Since then, so many requests are being sent to the external URL that it detects a DoS attack and shuts me out!
I removed the redirection code and replaced it with the web.config changes for Forms Auth - and the same thing happened...
Why not use Microsoft Geneva instead of attempting to roll your own authentication provider?
CODE:
public class MyAuthenticate : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
if (filterContext.HttpContext.Session["user"] == null)
{
using (Authenticator dp = new Authenticator())
{
MyUser mu;
string data = string.Empty;
try
{
data = filterContext.HttpContext.Request["Data"];
}
catch { };
if (!string.IsNullOrEmpty(data))
{
mu = dp.Redeem(data);
if (mu.authenticated)
{
filterContext.HttpContext.Session.Clear();
AuthenticatedUser user = new AuthenticatedUser(mu);
filterContext.HttpContext.Session.Add("user", user);
FormsAuthentication.SetAuthCookie(user.UserId, false);
}
else
{
filterContext.HttpContext.Response.Redirect("MY EXTERNAL URL GOES HERE!!");
}
}
else
{
filterContext.HttpContext.Response.Redirect("MY EXTERNAL URL GOES HERE!!");
}
}
}
base.OnActionExecuting(filterContext);
}
}
}
I resolved this issue by creating a static dictionary of requesting IPs, and dropping duplicate requests from the same IP. Not a very nice solution - so if anyone figures out a better solution - let me know.