小编joh*_* Gu的帖子

如何在使用Delete链接删除对象时包含@ Html.AntiForgeryToken()

我有以下ajax.actionlink调用Delete action method删除对象: -

 @if (!item.IsAlreadyAssigned(item.LabTestID))
        { 
        string i = "Are You sure You want to delete (" + @item.Description.ToString() + ") ?";
           @Ajax.ActionLink("Delete",
       "Delete", "LabTest",
      new { id = item.LabTestID },

new AjaxOptions
{ Confirm = i,
    HttpMethod = "Post",
    OnSuccess = "deletionconfirmation",
    OnFailure = "deletionerror"
})
} 
Run Code Online (Sandbox Code Playgroud)

但有一个办法,包括@Html.AntiForgeryToken()Ajax.actionlink删除通话,以确保没有任何攻击者可以通过发送虚假的删除请求?

BR

antiforgerytoken asp.net-mvc-3

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

使用实体框架从两个数据库连接表

我正在研究ASP.NET MVC 4 Web应用程序.我使用Entity Framework作为数据访问层,使用数据库第一种方法(.edmx文件).

目前我在两个不同数据库中定义的连接表中存在问题(即我有两个.edmx文件).

例如,如果我想连接表,我正在执行以下查询: -

public ActionResult AutoComplete(string term)
{
   var tech = repository.AllFindTechnolog(term).Take(100);//Call to the first database
   var resources = repository.GetResources(tech.Select(a => a.IT360ID.Value).ToArray(), false);//call to the second database

   var query = from techItems in tech
         join resourcesItems in resources
         on techItems.IT360ID.Value equals resourcesItems.RESOURCEID // join based on db2ID
         orderby techItems.PartialTag
         select new //code goes here

   return Json(query, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)

我将对数据库进行两次单独调用,并在应用程序服务器内部进行连接,这不是最佳的面向性能的解决方案.理想情况下,连接将完全在数据库引擎内部发生.

我知道存储过程将允许我纯粹在服务器上连接来自不同数据库的表,但我不想使用SP,因为它会使我的代码不易维护且不易测试.

所以我正在寻找一个解决方案,我可以使用实体框架进行连接并导致单个数据库连接?

linq asp.net-mvc entity-framework entity-framework-5

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

如何在我的asp.net mvc中的脚本文件中获取当前登录用户名

我有一个脚本文件调用JSON API,我需要发送当前登录用户名作为调用的一部分.我尝试了以下方法: -

    $(document).ready(function () {
        var name = prompt("Please enter your packageid", "test");

        var fullurl = 'http://localhost:8080/jw/web/json/workflow/process/list?j_username=kermit&hash=9449B5ABCFA9AFDA36B801351ED3DF66&loginAs=' + HttpContext.Current.User.Identity.Name + 'packageId=' + name;
        $.ajax({
            type: "GET",
            url: fullurl,
            dataType: "JSONP",
            success: function (result) {
//code goes here
Run Code Online (Sandbox Code Playgroud)

但它会引发以下错误: - 'HttpContext'未定义

javascript asp.net-mvc asp.net-mvc-4

11
推荐指数
1
解决办法
6万
查看次数

"BundleTable.EnableOptimizations = true;" 自动缩小文件或只选择.min(如果可用)

我需要知道指定"BundleTable.EnableOptimizations = true;"是否会自动缩小文件(js和Css),或者只选择.min(如果可用)?

asp.net-mvc bundle asp.net-mvc-5

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

如果我在IQueryable上使用await + ToListAsync()并且未定义为任务,那么它是否正确?

我正在使用带有EF-6的asp.net MVC-5,我不确定使用await + ToListAsync是否有效.例如,我有以下存储库方法,它返回IQueryable: -

public IQueryable<TSet> getAllScanEmailTo()
{
    return t.TSets.Where(a=>a.Name.StartsWith("ScanEmail"));    
}
Run Code Online (Sandbox Code Playgroud)

我称之为: -

var emailsTo = await repository.getAllScanEmailTo().ToListAsync();
Run Code Online (Sandbox Code Playgroud)

一开始,我以为我会得到一个错误,因为我正在使用"等待"一个未被定义为任务的方法,但上面工作得很好,所以有人可以就此提出建议吗?

c# asynchronous async-await entity-framework-6 asp.net-mvc-5

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

ViewBag名称可以与DropDownList中的Model属性名称相同吗?

我正在研究ASP.NET MVC-4 Web应用程序.我在我的action方法中定义了以下内容来构建一个SelectList:

ViewBag.CustomerID = new SelectList(db.CustomerSyncs, "CustomerID", "Name");
Run Code Online (Sandbox Code Playgroud)

然后我在我的DropDownListFor内部渲染我View:

 @Html.DropDownListFor(model => model.CustomerID, (SelectList)ViewBag.CustomerID, "please select")
Run Code Online (Sandbox Code Playgroud)

如图所示,我将ViewBag属性命名为等于Model属性名称CustomerID.从我自己的测试中,定义相同的名称不会导致任何问题或冲突,但我应该避免这种情况吗?

asp.net asp.net-mvc html-helper html.dropdownlistfor asp.net-mvc-4

11
推荐指数
1
解决办法
1339
查看次数

Visual Studio 2015 Professioanl引发以下错误: - 无法加载文件或程序集'Microsoft.Activities.Design.Services

我的Dev机器里面有以下内容: -

  1. Windows服务器r2 2012.
  2. SharePoint服务器2016.
  3. 我下载/安装Visual studio 2015 Professioanl.
  4. 我为Visual Studio 2015下载了Microsoft Office Developer Tools Preview 2
  5. 我在VS 2015社区内创建了一个新的空的sharepoint 2016项目.
  6. 在项目内部,我添加了一个新的事件接收器.
  7. 我成功地构建了项目.

但是当我点击开始调试时,得到了这个奇怪的异常: -

严重级代码说明项目文件行抑制状态错误无法加载一个或多个请求的类型.检索LoaderExceptions属性以获取更多信息.SharePointProject6

这是我的SP 2016解决方案的样子: -

在此输入图像描述

我的项目也显示了这个警告: -

严重级代码说明项目文件行抑制状态警告调用类型为'Microsoft.VisualStudio.SharePoint.WorkflowDesignerSupport.PackageBootstrapper,Microsoft.VisualStudio.SharePoint.WorkflowDesignerSupport,Version = 14.0.0.0,Culture = neutral,PublicKeyToken的方法'projectService_ProjectInitialized'时发生未处理的异常= b03f5f7f11d50a3a".例外:System.IO.FileNotFoundException.消息:无法加载文件或程序集"Microsoft.Activities.Design.Services,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = 31bf3856ad364e35"或其依赖项之一.该系统找不到指定的文件.SharePointProject6 0

所以有人可以就此提出建议吗?谢谢

编辑

这是参考文献

在此输入图像描述 : -

EDIT-2 当我从以下位置" C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5" 查看我当前的参考文献时,我得到以下内容: -

在此输入图像描述

编辑-3

现在我去到另一台机器它的Visual Studio 2015年安装了(其实这是我的dev的笔记本电脑),我复制Microsoft.Activities.Design.Services.dllC:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.Activities.Design.Services\v4.0_1.0.0.0__31bf3856ad364e35,然后我将其粘贴在我的服务器具有SharePoint和安装Visual Studio内: -

在此输入图像描述

然后我打开视觉工作室项目,我浏览Microsoft.Activities.Design.Services.dll,然后将其添加到我的visual studio项目中,如下所示: -

在此输入图像描述

但我仍面临同样的错误.现在我尝试运行visual studio作为Admin.Plus我清除我的项目的bin文件夹.另外我修复了视觉工作室,我修复了视觉工作室的开发工具......但是当我运行项目时,我会收到同样的错误......

Edit-4 现在我修复了Visual Studio 2015,我收到了以下消息: -

在此输入图像描述

所以我不确定这些消息是否与我面临的问题有关?

.net sharepoint visual-studio visual-studio-2015

11
推荐指数
1
解决办法
1037
查看次数

我应该使用HTTP引用者验证或令牌验证来防止CSRF攻击吗?

我读到了如何在ASP.NET MVC Web应用程序中保护我的网站免受CSRF攻击.他们提到了两种方法,可以通过以下方式:

  1. 使用<@Html.AntiForgeryToken()>和使用令牌验证[ValidateAntiforgeryToken]

  2. 使用HTTP引用者验证,例如:

    public class IsPostedFromThisSiteAttribute : AuthorizeAttribute
        {
        public override void OnAuthorize(AuthorizationContext filterContext)
            {
            if (filterContext.HttpContext != null)
                {
                if (filterContext.HttpContext.Request.UrlReferrer == null)
                    throw new System.Web.HttpException("Invalid submission");
                if (filterContext.HttpContext.Request.UrlReferrer.Host !=
                    "mysite.com")
                    throw new System.Web.HttpException
                        ("This form wasn't submitted from this site!");
                }
            }
        }
    
    Run Code Online (Sandbox Code Playgroud)

    [IsPostedFromThisSite]
    public ActionResult Register(…)
    
    Run Code Online (Sandbox Code Playgroud)

所以我很困惑我是否应该使用它们来保护我的网站免受CSRF攻击,或者我是否可以选择其中一种方法?

security csrf asp.net-mvc-3

10
推荐指数
1
解决办法
7311
查看次数

UriBuilder无法编码UriBuilder注册标志

我正在开发一个asp.net mvc Web应用程序.现在我的操作系统值等于: -

在此输入图像描述

我正在使用以下代码构建一个包含上述值的URL,如下所示: -

var query = HttpUtility.ParseQueryString(string.Empty);
query["osName"] = OperatingSystem;


var url = new UriBuilder(apiurl);
url.Query = query.ToString();
string xml = client.DownloadString(url.ToString());
Run Code Online (Sandbox Code Playgroud)

但生成的URL将包含操作系统的以下值: -

osName=Microsoft%u00ae+Windows+Server%u00ae+2008+Standard
Run Code Online (Sandbox Code Playgroud)

因此,%u00ae+当我尝试解码%u00ae+使用在线网站(例如http://meyerweb.com/eric/tools/dencoder/)时,UriBuilder会对已注册的符号进行编码,因此它不会解码%u00ae+为寄存器符号??? 所以,有人可以请求,我如何在我的网址内发送注册的标志?这是UrilBuilder中的一个问题吗?

谢谢

编辑 这将清楚地说明我的问题..现在我传递资产名称值,现在查询["assetName"]将获得正确的值..但在查询中,值将被错误地编码(将不能使用UTF8编码)!!!

在此输入图像描述

.net c# asp.net asp.net-mvc uribuilder

10
推荐指数
1
解决办法
613
查看次数

按我的json对象分组并获取每组的计数

我正在使用2个休息api服务.第一个将从名为"主要类别"的列表中获取项目如下: -

/test/_api/web/lists/getbytitle('MainCategory')/items?$select=Title
Run Code Online (Sandbox Code Playgroud)

它将返回以下json: -

{
    "d": {
        "results": [
            {                    
                "FileSystemObjectType": 0,
                "Id": 15,
                "ID": 15,
                "ContentTypeId": "0x010006DDBDD3BDC9914B92E911733F2A56E1",
                "Title": "A",
                "Modified": "2017-03-01T12:08:35Z",
                "Created": "2017-03-01T12:08:35Z",
                "AuthorId": 1,
                "EditorId": 1,
                "OData__UIVersionString": "1.0",
                "Attachments": false,
                "GUID": "c93d9db6-efd8-4b49-9024-f8cc30c0a48e"
            },
            {
                 "FileSystemObjectType": 0,
                "Id": 16,
                "ID": 16,
                "ContentTypeId": "0x010006DDBDD3BDC9914B92E911733F2A56E1",
                "Title": "B",
                "Modified": "2017-03-01T12:10:27Z",
                "Created": "2017-03-01T12:10:27Z",
                "AuthorId": 1,
                "EditorId": 1,
                "OData__UIVersionString": "1.0",
                "Attachments": false,
                "GUID": "a023853c-e967-4db8-8414-a7c390dcc09a"
            },
Run Code Online (Sandbox Code Playgroud)

我有另一个名为的列表Pages,其中每个页面链接到一个主类别项目.

/test/_api/web/lists/getbytitle('pages')/items??$select=Title,MainCategory&$filter=MainCategory eq
Run Code Online (Sandbox Code Playgroud)

这里是返回json: -

{
    "d": {
        "results": [
            {    
                "Title": "Home",
                "MainCategory": "A"
            }, …
Run Code Online (Sandbox Code Playgroud)

javascript rest jquery json

10
推荐指数
1
解决办法
3004
查看次数