小编Nie*_*ant的帖子

删除文件,但访问被拒绝

我有一个带有实体框架的mvc4应用程序.

我想删除一个文件,但每次都说:

mscorlib.dll中出现"System.UnauthorizedAccessException"类型的异常,但未在用户代码中处理

附加信息:访问路径'G:\ Mijn Documents\My Web Sites\Lolabikes - Copy\C#\ ContosoUniversity\Images \'被拒绝.

通过这一行:System.IO.File.Delete(path);

这是方法:

public ActionResult DeleteFiles(int id)
        {           
                //var fileName = Path.GetFileName(id.FileName);

                var DirSeparator = Path.DirectorySeparatorChar;
                var path = Server.MapPath("~\\Images" + DirSeparator);// + fileName.Replace('+', '_')));
               var file = db.lolabikerPhotos.Find(id);               
               System.IO.File.Delete(path);
               db.SaveChanges();           

            return Redirect(Url.Action("Edit", "Account") + "#tabs-3");

        }
Run Code Online (Sandbox Code Playgroud)

我只是在visual studio中运行应用程序,如下所示: http://localhost:41787/Account/Edit?UserId=hallo

我已经完成了以下事情:

完全访问地图,我将网络服务添加到地图并完全控制.但似乎没有任何效果.我正在使用Windows 7.我以管理员身份运行visual studio 2013

我也看到了这个:

ASP.NET is not authorized to access the requested resource. Consider granting access rights to the resource to the ASP.NET request identity. ASP.NET has …
Run Code Online (Sandbox Code Playgroud)

c# windows entity-framework asp.net-mvc-4 visual-studio-2013

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

使用asp.net mvc 4 + Entity Framework将图像保存到数据库

我有这个:

模型:

 public string Picture { get; set; }

 [Column(TypeName = "image")]
 public byte[] Image { get; set; }

 [Display(Name = "Display profile Image")]
 public bool DisplayItem { get; set; }
Run Code Online (Sandbox Code Playgroud)

视图:

<div class="editor-label">
    @Html.LabelFor(model => model.DisplayItem)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.DisplayItem)
    @Html.ValidationMessageFor(model => model.DisplayItem)
</div>
<div class="editor-label">
    @Html.LabelFor(m => m.Image)
</div>

<input type="file" name="file"/>
Run Code Online (Sandbox Code Playgroud)

和控制器:

public ActionResult Edit(string UserId)
{
        string username = User.Identity.Name;
        // Fetch the userprofile
        UserProfile user = db.userProfiles.FirstOrDefault(u => u.UserName.Equals(username));
        // Construct the viewmodel …
Run Code Online (Sandbox Code Playgroud)

c# database entity-framework-5 visual-studio-2012

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

导航,导航菜单下的白线,活动链接

我有这个:_Layout.cshtml

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - LolaBikeMen</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")
</head>
<body>



    <div class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                    <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>



                @Html.ActionLink("LolaBikeMen", "Index", "Home", null, new { @class = "navbar-brand" })
            </div>
            <div class="navbar-collapse collapse">
                <br />
                <div class="float-right">
                    @*<section id="login">
                        @Html.Partial("_LoginPartial")
                    </section>*@

                    <ul class="nav navbar-nav">
                        @*<li>@Html.ActionLink("Home", "Index", "Home")</li>*@
                        <li @if (@ViewContext.RouteData.GetRequiredString("controller") == "Account") { @Html.AttributeEncode("class=active")  ; }>
                            @Html.ActionLink("WHO", "Index", "Account")
                        </li> …
Run Code Online (Sandbox Code Playgroud)

css asp.net-mvc-4 twitter-bootstrap visual-studio-2012

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