ASP.net实现上传APK文件并且下载APK
来源:互联网 发布:编程资料 编辑:程序博客网 时间:2024/06/11 02:34
前言:文中所讲仅为个人学习使用过程中的一些经验和想法,望多提意见。
一,实现上传APK文件的功能
界面cs.html代码:
<strong> </strong><span style="font-weight: bold; white-space: pre;"></span>@*enctype= "multipart/form-data"是必需有的,否则action接收不到相应的file*@ @using (Html.BeginForm("AddVersion", "Home", FormMethod.Post, new { enctype = "multipart/form-data" })) { <label>VerName:</label> @Html.TextBox("VerName", "", new { style="width:100%;"}); <br/> <label>VerCode:</label> @Html.TextBox("VerCode", "", new { style = "width:100%;"}); <br/> <label>DownLoadUrl:</label> @Html.TextBox("DownLoadUrl", "", new { style = "width:100%;"}); <br/> <label>DesCription:</label> @Html.TextBox("DesCription", "", new { style="width:100%;"}); <br/> <span>文件上传</span> <br> <input type="file" name ="file" /> <br/> <input type="submit" value="提交"/> }controller中的代码:
<span style="white-space:pre"></span>if (file == null) { return Content("没有文件!", "text/plain"); } var fileName = Path.Combine(Request.MapPath("~/Upload/App"), Path.GetFileName(file.FileName)); try { file.SaveAs(fileName); //tm.AttachmentPath = fileName;//得到全部model信息 ///tm.AttachmentPath = "../upload/" + Path.GetFileName(file.FileName); //return Content("上传成功!", "text/plain"); // return RedirectToAction("Show", tm); return RedirectToAction("EditVersion"); } catch { return Content("上传异常 !", "text/plain"); }这样就可以实现文件的上传功能,没有使用JQuery,相对容易点。
(注:在这里上传文件有个问题,就是asp.net默认的最大上传文件是4M,运行超时为90s。解决这个问题我的方法是:修改web.config文件改默认值,添加这样一段代码:
<configuration> <system.web> <httpRuntime maxRequestLength="1048576" executionTimeout="3600" /> </system.web> <configuration>
更多解决办法可见:http://www.cnblogs.com/akwwl/p/3573666.html
)二,实现APK文件的下载
在ASP.net中直接把.apk文件放到/Upload/App路径下,然后发布完了以后,通过http://xxx/Upload/App/xx.apk是访问不了的。解决思路:将asp.net mvc路由忽略.apk文件请求URL映射
具体方法:
在web.config中:
<configuration> <configSections> ... <section name="rewriter" requirePermission="false" type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" /><!--加入此行--> </configSections> ... <system.web> <httpModules> <add name="UrlRewriter" type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter" /><!--加入此行--> </httpModules> ... </system.web> </configuration>在App_Start/RouteConfig.cs文件中
public class RouteConfig { public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.IgnoreRoute("{resource}.apk");// 加入此行 ... } }在IIS中配置MIME文件映射
运行->inetmgr
点确定
点中间的:MIME类型
输入需要配置的参数就可以了
0 0
- ASP.net实现上传APK文件并且下载APK
- ASP下载服务器apk文件
- 关于ASP.NET MVC4中,下载APK文件错误
- asp.net apk文件不能直接下载的解决方法
- ASP .net 实现文件上传 下载功能
- 从asp空间下载apk文件
- 【No3.】实现使用Service下载APK文件
- Python脚本实现自动下载apk文件
- ASP.NET[IIS]服务器上无法下载.apk文件解决方案 编辑:吴立星
- android apk文件下载
- IIS下载APK文件
- RXDownload实现下载apk
- ASP.NET实现文件的上传和下载
- Asp.net实现文件上传
- ASP.NET实现文件上传
- Asp.net实现文件上传
- asp.net实现上传文件
- asp.net 实现上传文件
- MyEclipse2014快速配置Spring & Spring Testing, Spring AOP简单使用
- 天声人語 20150724
- JAVA流操作(2)文件流
- Lowest Common Ancestor of a Binary Search Tree
- oracle 数据库设计的一些原则
- ASP.net实现上传APK文件并且下载APK
- ava.math.BigDecimal的用法
- Ilist 与 list 的区别
- linker command failed with exit code 1 错误小结
- Fragment生命周期
- Mybatis与Ibatis比较
- Android如何反编译xml文件 ,和防止代码反编译
- Android Studio之gradle的配置与介绍
- RHEL5下编译2.6.26.5内核