我正在创建一个生成随机数的密码生成器,然后我使用ascii将其转换为一个字母.在for循环中,我需要字母来转换字符串而不是列表.它可以工作,但它只是将随机字母显示为列表.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
class MainClass
{
static void Main()
{
int x = 1;
int length;
string a = "Press any key to continue";
object num;
while (x == 1)
{
Console.WriteLine("How many Characters would you like the Password to be? (Press -1 to Stop)");
length = Convert.ToInt32(Console.ReadLine());
try
{
for (int i = 0; i < length; i++)
{
int num1 = Number();
Int32 ASCII = num1;
num = (char)num1;
if …Run Code Online (Sandbox Code Playgroud) 对于我的MVC4应用程序,在Azure中运行,我将会话存储在共存的缓存中.如Microsoft提供的本方法文档中所述.
我运行两个小实例,一切似乎都运行正常.我可以登录到应用程序,当我在应用程序中浏览时,我仍然保持登录状态.因此,会话似乎适用于两个实例.
但是,当我更新会话数据时,如下所示:
HttpContext.Current.Session["someVar"] = "new value";
Run Code Online (Sandbox Code Playgroud)
该更改似乎只对处理该特定请求的实例产生影响.现在,当我浏览应用程序时,有时我得到初始值,有时我得到更新的值.
我没有对web.config进行任何更改,因此它看起来与Nuget包添加时完全一样:
<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
<providers>
<add name="AppFabricCacheSessionStoreProvider"
type="Microsoft.Web.DistributedCache.DistributedCacheSessionStateStoreProvider, Microsoft.Web.DistributedCache"
cacheName="default"
useBlobMode="true"
dataCacheClientName="default" />
</providers>
</sessionState>
Run Code Online (Sandbox Code Playgroud)
在使用Azure缓存时,是否需要以其他方式处理会话,或者这是我在这里缺少的其他内容?
我正在尝试在两个Web角色实例上运行的共存缓存上使用会话状态提供程序进行Windows Azure缓存.我有一个ASP.NET MVC4项目.我按照微软的指导如何设置它,并经历了多次,但结果相同.当我发布到Azure时,我在每个页面上都有一个YSOD.
我已经浏览了我的Azure实例上的日志,发现了可能导致此问题的异常:
Event code: 3008
Event message: A configuration error has occurred.
...
Exception information:
Exception type: DataCacheException
Exception message: ErrorCode<ERRCMC0003>:SubStatus<ES0001>:Error in client configuration file.
at Microsoft.ApplicationServer.Caching.ConfigFile.ThrowException(Int32 errorCode, Exception e)
at Microsoft.ApplicationServer.Caching.ClientConfigReader.Init(String path)
at Microsoft.ApplicationServer.Caching.DataCacheFactoryConfiguration..cctor()
Unrecognized element 'autoDiscover'. (E:\sitesroot\0\web.config line 20)
at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, …Run Code Online (Sandbox Code Playgroud) 我上传了4个对象到S3.对象键如下:
4eec12eb0a588620cccad16f/MumDad70s.jpg
4eec12eb0a588620cccad16f/NathanI-1.jpg
4eec12eb0a588620cccad16f/ProfilePic.png
4eec12eb0a588620cccad16f/nathan-orange.jpg
Run Code Online (Sandbox Code Playgroud)
我请求对象的代码是:
var req = new ListObjectsRequest()
.WithBucketName(BucketName)
.WithPrefix(jobid + "/")
.WithDelimiter("/");
var objs = _s3Client.ListObjects(req);
Run Code Online (Sandbox Code Playgroud)
在响应中,即使前缀实际上不是它自己的对象,而是仅仅是实际对象的键前面的字符串,我得到以下5个对象返回:
4eec12eb0a588620cccad16f/
4eec12eb0a588620cccad16f/MumDad70s.jpg
4eec12eb0a588620cccad16f/NathanI-1.jpg
4eec12eb0a588620cccad16f/ProfilePic.png
4eec12eb0a588620cccad16f/nathan-orange.jpg
Run Code Online (Sandbox Code Playgroud)
为什么返回的前缀好像是一个唯一的对象?如何只返回具有指定前缀的文件,而不必对列表进行后置过滤以摆脱前缀对象?
这个问题可能以前发过,但我找不到了.
我已经写了这么长时间的东西,我坐下来写一些新东西,然后开始输入这个就好像它是我自己的模式.最近出现了一个项目,我发现自己正在查看自己的代码并开始思考它看起来有多臭.
BackgroundInfoIfYouCare
Run Code Online (Sandbox Code Playgroud)
在这个特定的库中,我需要向用户发送电子邮件.到目前为止,有13个固定电子邮件.
每封电子邮件都有自己的模板(我使用的是Razor解析器,因此模板是用cshtml编写的).每个电子邮件模板都有一个名称密钥字符串.每封电子邮件都有自己的EF4查询,以根据"成员资格"实体和所有相关数据返回模型.
我有一个接受字符串的类,这是一个电子邮件模板名称密钥.
该方法将运行相应的查询并返回列表,抓取电子邮件模板.
列表和模板将传递给解析器,以将每个成员资格合并到模板中,并返回列表电子邮件.
EndOfBackgroundInfoIfYouCare
Run Code Online (Sandbox Code Playgroud)
真正的问题是......最好的方法是什么?
一种方法是只使用一个开关
public List<Membership> Execute(string TemplateKey) {
switch (TemplateKey)
{
case "SomethingExpired":
QueryResult = new SomethingExpiredEmailQuery().ExecuteQuery();
break;
case "SomethingExpireIn30":
QueryResult = new SomethingExpireIn30EmailQuery().ExecuteQuery();
break;
case "FirstTimeLoginThanks":
QueryResult = new FirstTimeLoginThanksEmailQuery().ExecuteQuery();
break;
case "SecurityTraining":
QueryResult = new SecurityTrainingEmailQuery().ExecuteQuery();
break;
case ETC ETC ETC...
Run Code Online (Sandbox Code Playgroud)
}
另一种方法是使用接口
IEmailQuery
void ExecuteQuery()
Run Code Online (Sandbox Code Playgroud)
但是如果我使用接口,我仍然需要实例化Query类.它不会保存任何代码,也不会使代码更易于维护.
通过反射,我可以使用模式命名所有电子邮件查询:电子邮件模板SecurityTraining的密钥具有SecurityTrainingEmailQuery的查询名称,我可以使用反射来实例化并调用ExecuteQuery方法.
如果不使用反射,是否有更清洁的连线方式?
我有以下两种方法从我的数据库中获取数据并返回一个填充的SelectList对象(包括一个"All"选项值),然后我将其传递给我的视图.问题是它们几乎完全相同,除了它们都访问不同的存储库对象并且它们具有不同的ID名称(StatusId和TeamId).我认为有机会将它们重构为一个接受存储库作为参数的方法,并以某种方式计算出ID名称应该是什么,可能是通过使用反射或某种lambda表达式,但我不知道如何实现这一目标.
private SelectList GetStatusSelectList(int selectedStatusId)
{
List<MemberStatus> statusList = _memberStatusRepository.All().ToList();
statusList.Insert(0, new MemberStatus {StatusId = 0, Name = "All"});
var statusSelectList = new SelectList(statusList, "StatusId", "Name", selectedStatusId);
return statusSelectList;
}
private SelectList GetTeamSelectList(int selectedTeamId)
{
List<MemberTeam> teamList = _memberTeamRepository.All().ToList();
teamList.Insert(0, new MemberTeam { TeamId = 0, Name = "All" });
var teamSelectList = new SelectList(teamList, "TeamId", "Name", selectedTeamId);
return teamSelectList;
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以帮助弄清楚如何将这些重构为一个方法?
我正在使用Wowza Media Server来启用MP4文件的流媒体,而我使用Flowplayer作为视频播放器.
为了获得我的内容的一些结构,我在StorageDir我的Wowza应用程序的配置中使用子目录.
我遇到的问题是,无论我使用什么URL格式,Wowza都会继续在根存储目录中查找该文件.
我已经使用Wowza指定的URL格式试图在这里,但没有运气:
rtmp://[wowza-ip-address]/myapp/_definst_/mp4:mysubdirectory/sample.mp4
Run Code Online (Sandbox Code Playgroud)
我还尝试了Wowza论坛帖子中建议的所有内容:
但是Wowza一直在寻找根存储目录,抛出这样的异常:
404 b0c9be70-a33c-41ce-9692-199e3a1caccf.mp4
open: java.io.FileNotFoundException:
C:\Program Files (x86)\Wowza Media Systems\Wowza Media Server 3.6.2\content\b0c9be70-a33c-41ce-9692-199e3a1caccf.mp4.flv
(The system cannot find the file specified)
Run Code Online (Sandbox Code Playgroud)
不知何故,Wowza认为它应该在根存储目录中查找FLV文件,即使URL指定它是子目录中的MP4文件.这是为什么?
我正在将视图从[HttpPost]方法重定向到[HttpGet]方法.我已经开始工作,但想知道这是否是最好的方法.
这是我的代码:
[HttpPost]
public ActionResult SubmitStudent()
{
StudentViewModel model = TempData["model"] as StudentResponseViewModel;
TempData["id"] = model.Id;
TempData["name"] = model.Name;
return RedirectToAction("DisplayStudent");
}
[HttpGet]
public ActionResult DisplayStudent()
{
ViewData["id"] = TempData["id"];
ViewData["name"] = TempData["name"];
return View();
}
Run Code Online (Sandbox Code Playgroud)
视图:
<%@ Page
Language="C#"
Inherits="System.Web.Mvc.ViewPage"
%>
<html>
<head runat="server">
<title>DisplayStudent</title>
</head>
<body>
<div>
<%= ViewData["id"]%> <br />
<%= ViewData["name"]%>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我有以下代码,我正在尝试检索id不包含该单词的txtbox OT.
<input type="text" id="txtMo1">
<input type="text" id="txtOTMo1">
<input type="text" id="txtTu1">
<input type="text" id="txtOTTu1">
...
...
<input type="text" id="txtMo4">
<input type="text" id="txtOTMo4">
<input type="text" id="txtTu4">
<input type="text" id="txtOTTu4">
...
...
Run Code Online (Sandbox Code Playgroud)
我尝试使用.find哪里id开始,txt但它给了我一切(显然).如何只检索id开头txt但不包含的文本框OT?
.find("input[id ^= 'txt']")
Run Code Online (Sandbox Code Playgroud) 我有一个ASP.NET MVC3应用程序,我使用Entity Framework 4.3 Code-First和Migrations.
我一直在尝试在相同类型的实体之间创建多对多关系,但是当我使用迁移构建迁移时,它会生成一对一的关系.
这个想法是一个用户应该能够跟随多个其他用户(想想Twitter).
我的User模型看起来像这样:
public class User
{
public int UserId { get; set; }
public string Name { get; set; }
public DateTime Registered { get; set; }
...
public virtual ICollection<User> Follows { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我支持添加的Follows-property时,我得到这样的迁移:
public partial class FollowUser : DbMigration
{
public override void Up()
{
AddColumn("User", "User_UserId", c => c.Int());
AddForeignKey("User", "User_UserId", "User", "UserId");
CreateIndex("User", "User_UserId");
}
...
}
Run Code Online (Sandbox Code Playgroud)
因此,实体框架将我的模型解释为两个用户之间的一对一关系.
如何在相同类型的实体之间创建多对多关系?
c# entity-framework ef-code-first asp.net-mvc-3 ef-migrations
c# ×6
asp.net-mvc ×3
asp.net ×2
azure ×2
amazon-s3 ×1
flowplayer ×1
http-get ×1
http-post ×1
jquery ×1
refactoring ×1
reflection ×1
selectlist ×1
wowza ×1