小编Md.*_*man的帖子

如何在空MVC 4项目模板中添加ASP.NET成员资格提供程序?

我是ASP.NET MVC4的新手.我正在创建一个空的MVC4项目模板,并尝试添加ASP.NET成员资格提供程序,但我不知道我该怎么做.我在谷歌搜索,但所有演示都使用Internet应用程序项目模板.

我知道这个问题并不好,但我已经花了两天时间.

请为此目的提供一些建议或教程.

更新

根据Nesim Razon的建议,我将表单身份验证部分从MVC4 Web应用程序(Internet应用程序模板)复制并粘贴到我的空项目中.但现在我得到一个异常要调用此方法,"Membership.Provider"属性必须是"ExtendedMembershipProvider"的实例.

[InitializeSimpleMembership]
public class HomeController : Controller
{

    public ActionResult Index()
    {
        WebSecurity.CreateUserAndAccount("Name", "Password"); // Exception is thrown from there.
        return View();
    }

}
Run Code Online (Sandbox Code Playgroud)

我还在Web.config文件中添加了以下指令:

<add key="enableSimpleMembership" value="true" /> 
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc membership-provider asp.net-mvc-4

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

如何在我的网站上托管我的WCF服务?

我是WCF的新手.我开发了一个示例WCF服务.我的服务使用basicHttp绑定.

我使用WAS在本地IIS 7.5中托管我的服务,它工作正常.现在我想在我的网站上托管我的服务.

我搜索谷歌但其中大部分都托管在IIS的localhost中.请告诉我该怎么做?最好引用一些教程或分步指南.

asp.net iis hosting wcf

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

未捕获的SyntaxError:在MVC4中捆绑两个CSS文件之后出现意外的令牌异常

在我的MVC4项目中,我捆绑了两个css文件.当浏览呈现此文件时,我有两个例外.

Uncaught SyntaxError: Unexpected token .
Uncaught SyntaxError: Unexpected token {  
Run Code Online (Sandbox Code Playgroud)

我写了这个代码来捆绑我的CSS文件.

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new StyleBundle("~/Content/css")
    .Include("~/Content/css3.css","~/Content/styles.css"));
}
Run Code Online (Sandbox Code Playgroud)

我在_Layout.chshtml页面中调用它.

<head>
   @Scripts.Render("~/Content/css")
</head>
Run Code Online (Sandbox Code Playgroud)

得到那个例外.

但是,如果我以这种方式调用这些CSS文件,那么每件事都可以.

<head>
    <link href="~/Content/css3.css" rel="stylesheet" />
    <link href="~/Content/styles.css" rel="stylesheet" />
</head>
Run Code Online (Sandbox Code Playgroud)

这是我的错误的屏幕截图.

在此输入图像描述

css asp.net-mvc optimization bundle asp.net-mvc-4

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

为什么MVC 5不调用我的VirtualPathProvider类的GetFile方法?

我正在尝试从数据库加载Razor View.

在MVC 5中遵循ASP.NET MVC和虚拟视图以及VirtualPathProvider来做到这一点.

我的代码:

VirtualPathProvider:

 public class DbPathProvider : VirtualPathProvider
  {
    public override bool FileExists(string virtualPath)
    {
        var page = FindPage(virtualPath);
        if (page == null)
        {
            return base.FileExists(virtualPath);
        }
        else
        {
            return true;
        }
    }

    public override VirtualFile GetFile(string virtualPath)
    {
        var page = FindPage(virtualPath);
        if (page == null)
        {
            return base.GetFile(virtualPath);
        }
        else
        {
            return new DbVirtualFile(virtualPath, page.PageData.ToArray());
        }
    }

    private SiteModel FindPage(string virtualPath)
    {
        var db = new DatabaseContext();
        var …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc razor

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

错误CS0030:无法在Amazon Web Service中将类型'Simple.Amazon.ECS.ImageSet []'转换为'Simple.Amazon.ECS.ImageSet'

我正在尝试制作一个小型应用程序,可以通过它的ISBN搜索亚马逊的书.我是亚马逊网络服务的新手.

我关注以下链接:

http://flyingpies.wordpress.com/2009/08/01/17/

http://flyingpies.wordpress.com/2009/08/13/signing-amazon-product-advertising-api-cwcf-part-2/

使用新的亚马逊服务搜索亚马逊示例

我的代码是:

BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
binding.MaxReceivedMessageSize = int.MaxValue;

AWSECommerceServicePortTypeClient amazonClient = new AWSECommerceServicePortTypeClient(
    binding, new EndpointAddress("https://webservices.amazon.com/onca/soap?Service=AWSECommerceService"));

amazonClient.ChannelFactory.Endpoint.Behaviors.Add(new AmazonSigningEndpointBehavior(AccessKeyId, SecretAccessKey));

ItemLookup lookup = new ItemLookup();
ItemLookupRequest request = new ItemLookupRequest();

request.IdType = ItemLookupRequestIdType.ISBN;
request.ItemId = new[] {"9780297870470"};
request.ResponseGroup = new[] { "OfferSummary" };
request.SearchIndex = "All";
request.IdTypeSpecified = true;

lookup.Request = new ItemLookupRequest[] { request };
lookup.AWSAccessKeyId = AccessKeyId;
lookup.AssociateTag = "wwwyaodaromane-90";
var response = amazonClient.ItemLookup(lookup);
Run Code Online (Sandbox Code Playgroud)

当我尝试发送请求时,我得到了这个例外

序列化消息体ItemSearchRequest1时出错:'无法生成临时类(结果= 1).

错误CS0030:无法将类型'Simple.Amazon.ECS.ImageSet []'转换为'Simple.Amazon.ECS.ImageSet'

内部例外是:

{"无法生成临时类(结果= 1).\ r …

.net c# wcf amazon amazon-product-api

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

如何删除所有Click事件处理程序?

可能重复: 如何删除Button的Click事件的所有事件处理程序?

我想从按钮中删除所有单击事件处理程序.我在Stack Overflow问题中找到了这个方法如何从控件中删除所有事件处理程序.

private void RemoveClickEvent(Button b)
{
    FieldInfo f1 = typeof(Control).GetField("EventClick",
                                            BindingFlags.Static |
                                            BindingFlags.NonPublic);
    object obj = f1.GetValue(b);
    PropertyInfo pi = b.GetType().GetProperty("Events",
                                              BindingFlags.NonPublic |
                                              BindingFlags.Instance);
    EventHandlerList list = (EventHandlerList)pi.GetValue(b, null);
    list.RemoveHandler(obj, list[obj]);
}
Run Code Online (Sandbox Code Playgroud)

但是这一行总是返回null:

  typeof(Control).GetField("EventClick", BindingFlags.Static | BindingFlags.NonPublic);
Run Code Online (Sandbox Code Playgroud)

这种方法写于2006年.

这个方法有最新版本吗?

注意:我正在使用WPF.NET 4.0.

.net c# wpf event-handling

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

如何模拟Entity Framework 6异步方法?

我是嘲笑的新手.我想模拟我的基础存储库,它依赖于Entity Framework 6 DbContext但是我失败了.我在Google搜索了很多但没有得到任何足够的结果.最后我得到了一个使用异步查询进行测试的示例,并尝试关注但它对我有用.

这是我的代码:

DbContext:

public class TimeSketchContext : DbContext
{
    public virtual DbSet<EmployeeSkill> EmployeeSkill { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

基础知识库:

public class BaseRepository<T> : IRepositoryBase<T> where T : class, IEntity, new()
{
    protected readonly DbContext InnerDbContext;
    protected DbSet<T> InnerDbSet;

    public BaseRepository(DbContext innerDbContext)
    {
        InnerDbContext = innerDbContext;
        InnerDbSet = InnerDbContext.Set<T>();
    }

    public virtual Task<T> FindAsync(long id)
    {
        return InnerDbSet.FirstOrDefaultAsync(x=>x.Id == id);
    }
Run Code Online (Sandbox Code Playgroud)

}

测试:

    [Fact]
    public async Task DbTest()
    {
        var dummyData = GetEmployeeSkills();
        var …
Run Code Online (Sandbox Code Playgroud)

.net c# unit-testing entity-framework moq

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

如何在不使用.net中的属性的情况下映射dynamodb中的类属性

我是dynamodb的新手.我正在关注http://www.rkconsulting.com/blog/persistence-model-framework-with-aws-dynamodb 一步一步的教程,以便在dynamodb中进行连接和CRUD操作,它的工作正常.

在该教程中,他们使用属性映射来实现地图类属性

[DynamoDBTable("Dinosaur")]
public class Dinosaur
{
    [DynamoDBHashKey]
    public string Id { get; set; }

    [DynamoDBProperty(AttributeName = "Name")]
    public string Name { get; set; }

    [DynamoDBProperty(AttributeName = "HeightMetres")]
    public double HeightMetres { get; set; }

    [DynamoDBProperty(AttributeName = "WeightKG")]
    public double WeightKg { get; set; }

    [DynamoDBProperty(AttributeName = "Age")]
    public int Age { get; set; }

    [DynamoDBProperty(AttributeName = "Characteristics")]
    public List<string> Characteristics { get; set; }

    [DynamoDBProperty(AttributeName = "Photo", Converter = typeof(ImageConverter))]
    public Image Photo { get; set; } …
Run Code Online (Sandbox Code Playgroud)

.net c# amazon-s3 amazon-web-services amazon-dynamodb

6
推荐指数
2
解决办法
2226
查看次数

无法从文本'(RadButtonOnImage:RadButtonImage.Image)'创建'路径'

我为我的RadButton创建了一个附加属性来设置Button内容中的图像但是我在Visual Studio 2010中的设计时遇到了这个异常.在Blend 4中我没有显示任何错误,并且在运行时它工作正常.

附加财产:

namespace SmartSoft.GTS.RadButton
{
public class RadButtonImage
{
     public static readonly DependencyProperty ImagePropery;
     public static ImageSource GetImage(DependencyObject obj)
     {
         return (ImageSource)obj.GetValue(ImagePropery);
     }
     public static void SetImage(DependencyObject obj,ImageSource Value)
     {
         obj.SetValue(ImagePropery,Value);
     }
     static RadButtonImage()
     {
         ImagePropery = DependencyProperty.RegisterAttached("Image", typeof(ImageSource), typeof(RadButtonImage), new PropertyMetadata((ImageSource)null));
     }
   }
}
Run Code Online (Sandbox Code Playgroud)

XAML:

  xmlns:RadButtonOnImage="clr-namespace:SmartSoft.GTS.RadButton"

    <Style x:Key="ImageOnRadButton" TargetType="{x:Type telerik:RadButton}">
        <Setter Property="FontSize" Value="13.333"/>
        <Setter Property="ContentTemplate">
            <Setter.Value>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image Margin="5,0,5,0" HorizontalAlignment="Center" VerticalAlignment="Center"  Source="{Binding (RadButtonOnImage:RadButtonImage.Image), RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type telerik:RadButton}}}"/>
                        <TextBlock Text="{TemplateBinding Content}" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,0,5,0"/> …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml telerik

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

如何在现有数据库中添加表而不会丢失实体框架代码优先5.0中的数据?

最近我更新了我的软件,我需要在我的数据库中添加一个新表.我在用

Update-Database -Force -Verbose
Run Code Online (Sandbox Code Playgroud)

在我的开发PC中更新我的数据库.但是当我在我的客户机中安装我的软件的更新版本时,它会抛出以下异常.

The model backing the ‘MyContext’ context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269)
Run Code Online (Sandbox Code Playgroud)

如果我删除并重新创建数据库,那么它工作正常.

但是在我的客户机中删除现有数据库是不可能的.我必须添加我的新表而不会丢失任何数据.

请告诉我如何添加新表而不会丢失现有数据库中的数据.

我在用

Visual Studio 2012
Entity Framework 5.0
DotNet 4.0
MSSQL Server 2008 R2
Run Code Online (Sandbox Code Playgroud)

.net c# t-sql sql-server entity-framework

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