小编lea*_*...的帖子

Request.Url.Scheme在负载平衡站点上给出http而不是https

我正在测试新的负载平衡暂存站点,并且https是在负载均衡器级别设置的,而不是在站点级别.此外,这个网站将始终是https所以我不需要远程需要https属性等.网址显示https但它在我的代码中不可用.由于这个原因,我有一些问题

Request.Url.Scheme总是http:

public static string GetProtocol()
        {
            var protocol = "http";
            if (HttpContext.Current != null && HttpContext.Current.Request != null)
            {
                protocol = HttpContext.Current.Request.Url.Scheme;
            }
            return protocol;
        }
Run Code Online (Sandbox Code Playgroud)

与此基本URL相同,协议是http

public static string GetBaseUrl()
        {
            var baseUrl = String.Empty;

            if (HttpContext.Current == null || HttpContext.Current.Request == null || String.IsNullOrWhiteSpace(HttpRuntime.AppDomainAppPath)) return baseUrl;

            var request = HttpContext.Current.Request;
            var appUrl = HttpRuntime.AppDomainAppVirtualPath;

            baseUrl = string.Format("{0}://{1}{2}", request.Url.Scheme, request.Url.Authority, appUrl);

            if (!string.IsNullOrWhiteSpace(baseUrl) && !baseUrl.EndsWith("/"))
                baseUrl = String.Format("{0}/", baseUrl);

            return baseUrl;
        }
Run Code Online (Sandbox Code Playgroud)

现在最大的问题是引用样式表中引用的js文件和谷歌字体.我在这里使用//没有http或https,但这些被视为http,我在FireBug中看到混合内容被阻止的消息.

我怎样才能克服这个问题?

c# asp.net-mvc

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

MSMQ - 此计算机上尚未安装消息队列

我编写了一个示例应用程序来写入dev服务器上的公共和私有队列.我没有在本地计算机上安装消息队列.

我收到错误:此计算机上尚未安装消息队列.

错误在这一行:

MessageQueue.Exists(queueName)
Run Code Online (Sandbox Code Playgroud)

这是完整的测试代码,所有注释和未注释的私有和公共队列都会导致相同的错误.我在这做错了什么?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Messaging;

namespace MsmqTest
{
    public partial class Form1 : Form
    {
        //@"DIRECT=OS:devbox01\PRIVATE$\PrivateQueueDev";
        //@"DIRECT=TCP:192.168.6.102\PRIVATE$\PrivateQueueDev";
        private const string QueueName = @"DIRECT=TCP:192.168.6.102\PRIVATE$\PrivateQueueDev";


        //@"DIRECT=OS:devbox01\PublicQueueDev";
        //@"DIRECT=TCP:192.168.6.102\PublicQueueDev";
        private const string QueueNamePublic = @"DIRECT=TCP:192.168.6.102\PublicQueueDev";

        public Form1()
        {
            InitializeComponent();
        }

        private void Write_Click(object sender, EventArgs e)
        {
            MessageQueue msgQ;
            string msgText = String.Format("Message: {0}", DateTime.Now);
            try
            {
                msgQ = GetQ(QueueNamePublic);
                msgQ.Send(msgText);
            }
            catch (Exception ex)
            { …
Run Code Online (Sandbox Code Playgroud)

msmq

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

Highcharts工具提示格式化程序

因为this.x,当我通过代码推送数据时,我得到索引位置.如果我单独填充数据,如下面的代码,则this.x返回正确的项目.我该如何解决这个问题?

作品

xAxis: {
    categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},

series: [{
    data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]        
}]
Run Code Online (Sandbox Code Playgroud)

索引位置this.x在这里被推出

var points = [{
    Name: 'good',
    Y: '15000'
}, {
    Name: 'baad',
    Y: '3000'
}, {
    Name: 'wow',
    Y: '2000'
}];

var chartData = {
    GetChartSeries: function (points, name) {

        var seriesData = [];
        if (points != null && …
Run Code Online (Sandbox Code Playgroud)

tooltip highcharts

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

ASP.NET身份声明

我有一个问题,理解索赔,特别是角色.

以下给我分配给用户的两个角色

var roles = UserManager.GetRolesAsync(user.Id).Result;
Run Code Online (Sandbox Code Playgroud)

但是,当我得到索赔并迭代它时,我只获得第一个角色.我没有得到这两个角色.请注意,我在登录时没有在索赔中设置任何角色.

行动守则

IEnumerable<Claim> claims = null;
var identity = HttpContext.User.Identity as ClaimsIdentity;
if (identity != null && identity.Claims != null && identity.Claims.Any())
{
    claims = identity.Claims;
}
return View(claims);
Run Code Online (Sandbox Code Playgroud)

和相应的视图代码

@model IEnumerable<System.Security.Claims.Claim>
@{
    ViewBag.Title = "Display Claims";
}

<h2>Display Claims</h2>

@if (Model == null)
{
    <p class="alert-danger">No claims found</p>
}
else
{
    <table class="table table-bordered">
        <tr>
            <th>Subject</th>
            <th>Issuer</th>
            <th>Type</th>
            <th>Value</th>
        </tr>
        @foreach (var claim in Model.OrderBy(x => x.Type))
        {
            <tr>
                <td>@claim.Subject.Name</td>
                <td>@claim.Issuer</td>
                <td>@Html.ClaimType(claim.Type)</td>
                <td>@claim.Value</td> …
Run Code Online (Sandbox Code Playgroud)

c# asp.net claims-based-identity asp.net-identity

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

DataAnnotations - 验证未发生

验证在本地盒子,开发站点上正常工作但在登台和生产站点上没有发生.客户端和服务器端验证都没有发生.分段和生产都是负载平衡的,但由于某些其他功能要求而使用粘性连接.

我已经检查了所有环境中的bin文件夹,我在那里看到了以下两个dll.

DataAnnotationsExtensions.ClientValidation.dll
DataAnnotationsExtensions.dll
Run Code Online (Sandbox Code Playgroud)

在服务器端,以下应该失败但不会发生.

!TryValidateModel(model) || !ModelState.IsValid
Run Code Online (Sandbox Code Playgroud)

此站点使用Windows身份验证.

Web.config文件

<appSettings file="Configs\AppSettings_LocalHost.config">
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
Run Code Online (Sandbox Code Playgroud)

出于测试目的,我目前不使用捆绑包.对于捆绑包,我甚至用以下测试它

<location path="~/Content">
        <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
        </system.web>
    </location>
    <location path="~/bundles">
        <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
        </system.web>
    </location>
    <location path="~/Scripts">
        <system.web>
            <authorization>
                <allow users ="*" />
            </authorization>
        </system.web>
    </location>
Run Code Online (Sandbox Code Playgroud)

我也引用了以下JS文件

<script src="/NetSite/Scripts/Core/jquery.validate.min.js?v=1.12" type="text/javascript"></script>
<script src="/NetSite/Scripts/Core/jquery.validate.unobtrusive.min.js?v=1.12" type="text/javascript"></script>
<script src="/NetSite/Scripts/Custom/Validators.js?v=1.12" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

该应用程序是MVC 5,所有都是通过NuGet包添加的.我没有在服务器上安装MVC.我在这些服务器上有另一个MVC 5应用程序,验证正常.

这里是表单标签,第二个工作应用程序使用相同的表单标签.

using (Html.BeginForm(ActionNames.Index, ControllerNames.Rankings, …
Run Code Online (Sandbox Code Playgroud)

validation asp.net-mvc data-annotations

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

类型“ System.Web.IHtmlString”在未引用的程序集中定义

现在有点迷路了...

我正在关注以下文章,以测试/学习嵌套布局。 http://blogs.msdn.com/b/marcinon/archive/2010/12/15/razor-nested-layouts-and-redefined-sections.aspx

而且我收到以下错误:

The type 'System.Web.IHtmlString' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. D:\Projects\Mvc3\Tests\RazorLayouts\Layout.MvcBase\Extensions\SectionExtensions.cs 15 36 Layout.MvcBase

我引用了名称空间System.Web ...,蓝线在“ RenderSection”上。公共静态HelperResult RenderSection

layout razor asp.net-mvc-3

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

MVC3为什么要使用html.editorfor

我正在看MVC3 razor示例,并看到html.editor被利用,并在此论坛上也被问了很多.为什么我不能使用html.textboxforpasswordfor?谢谢

razor asp.net-mvc-3

5
推荐指数
2
解决办法
5009
查看次数

在过滤器属性中获取区域、控制器和动作名称

我有全局属性,我需要知道区域、控制器和动作。由于路由(区域内注册和属性路由),我无法使用 RawUrl。我遵循了以下两种方法,但在这两种情况下,我的区域都返回空值。当我使用路线时,我得到的区域名称就好了。当我执行重定向操作或 url.action 或手动输入 url 等时,为什么我的区域为空?我们正在使用 MVC 5.0。

1:

var routingValues = RouteTable.Routes.GetRouteData(new HttpContextWrapper(HttpContext.Current)).Values;

                        var currentArea = (string) routingValues["area"] ?? string.Empty;
                        var currentController = (string) routingValues["controller"] ?? string.Empty;
                        var currentAction = (string) routingValues["action"] ?? string.Empty;
Run Code Online (Sandbox Code Playgroud)

2:

var handler = HttpContext.Current.Handler as System.Web.Mvc.MvcHandler;
                            var area = handler.RequestContext.RouteData.Values["area"];
                            var controller = handler.RequestContext.RouteData.Values["controller"];
                            var action = handler.RequestContext.RouteData.Values["action"];
Run Code Online (Sandbox Code Playgroud)

就像我上面说的,如果我使用路线(/TipHotLine),那么我就可以很好地获得区域名称。

public class AgencyAreaRegistration : AreaRegistration 
    {
        public override string AreaName 
        {
            get 
            {
                return "Agency";
            }
        }

        public override void RegisterArea(AreaRegistrationContext context) 
        {
            context.MapRoute(
                "Agency_default", …
Run Code Online (Sandbox Code Playgroud)

asp.net-mvc asp.net-mvc-routing

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

Mandrill模板中的条件内容

我将字典键(键值对)移交给服务,该服务又利用api通过Mandrill发送电子邮件.

现在,如果我的密钥是空白,那么我不希望它被包含在电子邮件中.就像在下面的场景中一样,我只希望显示链接文本,如果我的键有一些值.

<a href=" |UPDATE_PROFILE|"target="_blank">更改订阅偏好</a>

我怎么能写出一些类似的东西,甚至可能呢?

if *|UPDATE_PROFILE|* IS NOT EMPTY
BEGIN
<a href="*|UPDATE_PROFILE|*" target="_blank">change subscription preferences</a> 
END
Run Code Online (Sandbox Code Playgroud)

templates if-statement conditional-statements mandrill

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

Kentico 12 DancingGoat MVC SiteName 为空或为空

我已经安装了 DancingGoat MVC,我可以很好地访问 IIS url

http://localhost:8080/Kentico12_DancingGoatMvc

http://localhost:8080/Kentico12_Admin/Admin/cmsadministration.aspx

当我尝试调试 MVC 应用程序以查看示例站点的内部工作原理时,在 StartUp.auh.cs 文件中,我得到SiteName is empty or null exception.

例外在以下行

// Register Kentico Membership identity implementation
app.CreatePerOwinContext(() => UserManager.Initialize(app, new UserManager(new UserStore(SiteContext.CurrentSiteName))));
Run Code Online (Sandbox Code Playgroud)

我该如何纠正?

kentico

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