小编tho*_*lau的帖子

如何在c#中使用https?

我正在开发一个Web应用程序.为了用户信息的安全,我需要一个https连接.我现在正在开发这个地方.我已按照以下教程:http://weblogs.asp.net/dwahlin/archive/2009/08/25/requiring-ssl-for-asp-net-mvc-controllers.aspx

当我构建我的项目页面加载但网址是:http:// ...

在我的代码我已经放置:

    [RequiresSSL]
    public ActionResult Index()
    {
        //var model = Adapter.EuserRepository.GetAll();

        return View(db.Eusers.ToList());
    }
Run Code Online (Sandbox Code Playgroud)

网站代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace extranet.Helpers
{
    public class RequiresSSL: ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            HttpRequestBase req = filterContext.HttpContext.Request;
            HttpResponseBase res = filterContext.HttpContext.Response;

            //Check if we're secure or not and if we're on the local box
            if (!req.IsSecureConnection && !req.IsLocal)
            {
                var builder = new UriBuilder(req.Url)
                {
                    Scheme = Uri.UriSchemeHttps,
                    Port …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc https asp.net-mvc-4

5
推荐指数
1
解决办法
611
查看次数

从控制器中的ajax POST空接收参数+在firebug MVC 4中传递参数

我已经看过网,弄清楚我的错误是什么.我发现我尝试的所有建议都没有任何成功.我在控制器中访问httppost动作,但参数保持为空.

AJAX功能

var dataPost = { 'id': id, 'val': val };
                    debugger;
                    $.ajax({
                        type: 'POST',
                        url: '/Extensions/UpdateJson',
                        data: dataPost ,
                        contentType: 'json',
                        success: function () {
                            alert("succes");
                        },
                        error: function () {
                            alert("error");
                        }
                    });
Run Code Online (Sandbox Code Playgroud)

在调试DataPost时填充.

调节器

    [HttpPost]
    public ActionResult UpdateJson(string id, string val)
    {
        //do stuff
        return Json(true);
    }
Run Code Online (Sandbox Code Playgroud)

我在控制器中使用的参数与我的Ajax函数中的名称相同.传递的格式是json,我也尝试使用以下方法填充数据:

var dataPost = { 'id': 'id', 'val': 'val' };
Run Code Online (Sandbox Code Playgroud)

但这没有任何区别.我也尝试过使用类,比如 - >

public class ScheduleData
{
    public string id { get; set; }
    public string val { get; …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc jquery asp.net-ajax asp.net-mvc-4

3
推荐指数
1
解决办法
5974
查看次数

c#中serverdariables缺少HTTP_X_FORWARDED_FOR

我想获得ClientIPaddress但是当我打电话给Request.ServerVariables["HTTP_X_FORWARDED_FOR"]我时总是得到NULL.

检查后Servervariables我注意到HTTP_X_FORWARDED_FOR的列表中没有选项列表.

任何人都知道这是如何可能的以及如何解决?或者这个选项不在列表中并且我遗漏了一些东西是正常的.

提前致谢

c# asp.net ip

3
推荐指数
2
解决办法
2万
查看次数

在 MVC C# 中将 base64 转换为可下载的 zip 文件

我之前能够下载 zip 文件,但压缩发生在 ASP 服务器上。现在我们已将此操作更改为另一台服务器(进度)。

此时我收到一个表示 zip 文件的 Base64 编码字符串。但我怎样才能将这个字符串转换为 zip 文件。我之前使用的代码可以在下面找到,我可以重复使用代码吗?

MemoryStream outputStream = new MemoryStream();
outputStream.Seek(0, SeekOrigin.Begin);

using (ZipFile zip = new ZipFile())
{
   foreach (string id in idArray)
   {
        string json = rest.getDocumentInvoice(Convert.ToInt32(id));
        byte[] file = json.convertJsonToFile();
        zip.AddEntry("invoice" + id + ".pdf", file);
   }
    zip.Save(outputStream);
}


outputStream.WriteTo(Response.OutputStream);
Response.AppendHeader("content-disposition", "attachment; filename=invoices.zip");
Response.ContentType = "application/zip";
return new FileStreamResult(outputStream, "application/zip");
Run Code Online (Sandbox Code Playgroud)

我不知道如何将字符串转换为 zip 文件。在此先感谢您的帮助

c# asp.net-mvc zip base64

3
推荐指数
1
解决办法
2万
查看次数

在MVC4中上传,我的操作中有2个参数,但文件为空

我正在尝试将文件上传到目录.以下代码对我有用

CONTROLLER

[HttpPost]
        public ActionResult Index(HttpPostedFileBase uploadFile)
        {
            //string path = @"C:\Users\thomas\Desktop";

            if (uploadFile != null)
            {
                string filePath = Path.Combine(Server.MapPath("/files"), Path.GetFileName(uploadFile.FileName));
                uploadFile.SaveAs(filePath);
            }

            return RedirectToAction("Index");
        }
Run Code Online (Sandbox Code Playgroud)

HTML PAGE

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>
<form action="/Post/Index" method="post" enctype="multipart/form-data">
    <label for="uploadFile">Upload file: </label>
    <input name="uploadFile" id="uploadFile" type="file" />
    <input value="uploadFile" type="submit" />
</form>
Run Code Online (Sandbox Code Playgroud)

现在我正在尝试在一个函数中实现它,我创建一个消息,该消息由包含消息和项类的模型创建.当我提交表单时,模型将传递给我的savecontroller但在我的参数控制器中该文件为null.

HTML PAGE

创建新消息

@model GeoCitytroopers.Models.MessageItemModel
@{
    ViewBag.Title = "Create";
}
@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Event</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.Message.MessagePicture)
        </div>
        <div>
            <label for="uploadFile">Upload file: …
Run Code Online (Sandbox Code Playgroud)

forms upload file-upload httppostedfilebase asp.net-mvc-4

2
推荐指数
1
解决办法
1794
查看次数