小编Kah*_*anu的帖子

NuGet web.config.transform问题

我正在创建一个需要修改目标应用程序的web.config文件的自定义程序包,但我的配置更改在安装后永远不会出现在目标应用程序中.

这是我的web.config.transform文件:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="AppInstalled" value="false"/>
  </appSettings>
</configuration>

appSettings部分中的此键永远不会应用.

这是我的nuspec文件:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <authors>$author$</authors>
    <owners>$author$</owners>
    <licenseUrl>http://mvcapp.codeplex.com/license</licenseUrl>
    <projectUrl>http://mvcapp.codeplex.com/</projectUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$description$</description>
    <tags>mvc app</tags>
  </metadata>
  <files>
    <file src="\bin\Release\MvcApp.MVC3.dll" target="lib" />
    <file src="NuGet\Content\ajax-loader.gif" target="Content" />
    <file src="NuGet\Content\web.config.transform" target="web.config" />
    <file src="NuGet\Views\Install\Index.aspx" target="Views\Install\Index.aspx" />
  </files>
</package>

这是我从VS 2010命令提示符运行打包项目的命令:

nuget pack mvcapp.csproj

有任何想法吗?

谢谢.

asp.net-mvc transform nuget

9
推荐指数
1
解决办法
5555
查看次数

如何保持png透明度?

我创建了一个函数,允许上传的透明.png文件插入到SQL Server数据库中,并通过HttpHandler显示在网页上.

虽然这一切都有效,但是当在网页上查看时,png透明度会变为黑色.有没有办法保持透明度?

这是我从MVC控制器插入数据库的图像服务:

public void AddImage(int productId, string caption, byte[] bytesOriginal)
{
    string jpgpattern = ".jpg|.JPG";
    string pngpattern = ".png|.PNG";
    string pattern = jpgpattern;

    ImageFormat imgFormat = ImageFormat.Jpeg;

    if (caption.ToLower().EndsWith(".png"))
    {
    imgFormat = ImageFormat.Png;
    pattern = pngpattern;
    }

    ProductImage productImage = new ProductImage();
    productImage.ProductId = productId;
    productImage.BytesOriginal = bytesOriginal;
    productImage.BytesFull = Helpers.ResizeImageFile(bytesOriginal, 600, imgFormat);
    productImage.BytesPoster = Helpers.ResizeImageFile(bytesOriginal, 198, imgFormat);
    productImage.BytesThumb = Helpers.ResizeImageFile(bytesOriginal, 100, imgFormat);
    productImage.Caption = Common.RegexReplace(caption, pattern, "");

    productImageDao.Insert(productImage);
}
Run Code Online (Sandbox Code Playgroud)

这是"ResizeImageFile"辅助函数:

public static byte[] ResizeImageFile(byte[] imageFile, int targetSize, …
Run Code Online (Sandbox Code Playgroud)

c# png transparency image

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

Unity和ASP.NET WebForms - 没有为此对象定义的无参数构造函数

有没有人有任何关于如何使Unity 1.2或2.0与ASP.NET WebForms一起工作的好例子?

我以为我弄明白了,但显然我错过了一些东西.现在我收到了错误; "没有为此对象定义无参数构造函数".我记得几年前收到这个错误,我只是不记得我做了什么.

显然Unity并没有正常工作,因为我忘记了某些事情.任何帮助,将不胜感激.

这是我的一些代码:

Global.asax中

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

using Microsoft.Practices.Unity;

using PIA35.Unity;

namespace PIA35.Web
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            IUnityContainer container = Application.GetContainer();
            PIA35.Web.IoC.Bootstrapper.Configure(container);
        }
    }
}

这是web.config文件的httpModules部分:

<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add name="UnityHttpModule" type="PIA35.Unity.UnityHttpModule, PIA35.Unity"/>
</httpModules>

这是我的IoC bootstrapper类的代码.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Microsoft.Practices.Unity;

using PIA35.Services.Interfaces;
using PIA35.Services;
using PIA35.DataObjects.Interfaces; …

c# asp.net webforms unity-container

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

PropertyInfo.GetValue(myObject,null).GetType()返回"未将对象引用设置为对象的实例".

我正在尝试将MembershipUserCollection转换为要在GridView中使用的DataSet,我有这个帮助器类,它将循环遍历所有成员资格行和属性,并获取值和类型并将它们推送到DataRows.

它在有属性值时有效,但是当有一个空值时,它会中断返回消息"对象引用未设置为对象的实例.".

在这个特定的例子中,如果它的值为"null",它会在Comment字段中断.

这是我的代码:

    foreach (PropertyInfo oPropertyInfo in PropertyInfos)
    {
        Type oType = oPropertyInfo.GetValue(oData, null).GetType(); <-- error
        oDataRow[oPropertyInfo.Name.ToString()] = Convert.ChangeType(oPropertyInfo.GetValue(oData, null), oType);
    }
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

c# reflection properties propertyinfo

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

Ninject UnitOfWork 混淆

我一直将 Ninject 与我的 MVC 3 应用程序一起使用,但我正在尝试更改我的数据对象的模式以使用 UnitOfWork,但我无法弄清楚如何让 Ninject 正确处理这个问题。

我知道我的类实现在我的控制台应用程序中像这样手动构建时起作用:

IDatabaseFactory factory = new DatabaseFactory();
IUnitOfWork worker = new UnitOfWork(factory);
IBlogCategoryDao dao = new BlogCategoryDao(factory);
IBlogCategoryService service = new BlogCategoryService(dao);

BlogCategory category = service.GetById(id);

try
{
    if (category != null)
    {
    service.Delete(category);
    worker.Commit();
    Console.WriteLine("Category deleted successfully!");
    }
    else
    {
    Console.WriteLine("Entity doesn't exist.");
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error deleting category: {0}", ex.Message);
}
Run Code Online (Sandbox Code Playgroud)

在我的 MVC 3 应用程序中,我使用的是 Ninject.MVC3 NuGet 包,这是在 RegisterServices 方法中。

private static void RegisterServices(IKernel kernel)
{
    kernel.Bind<IDatabaseFactory>().To<DatabaseFactory>(); …
Run Code Online (Sandbox Code Playgroud)

unit-of-work ninject.web.mvc asp.net-mvc-3

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