这不一定是一个问题,我只是好奇它是如何工作的.我有一个方法:
public static bool UserIsAuthenticated()
{
bool isAuthed = false;
try
{
if (HttpContext.Current.User.Identity.Name != null)
{
if (HttpContext.Current.User.Identity.Name.Length != 0)
{
FormsIdentity id = (FormsIdentity)HttpContext.Current.User.Identity;
FormsAuthenticationTicket ticket = id.Ticket;
isAuthed = true;
string MyUserData = ticket.UserData;
}
}
}
catch { } // not authed
return isAuthed;
}
Run Code Online (Sandbox Code Playgroud)
在HttpContext.Current.User.Identity.Name返回null如果用户不存在,但它是如何知道哪些用户名存在或不存在?
目前我有一个名为ExistingFileName的自定义验证属性(下面),但我已经给它显示错误消息
protected override System.ComponentModel.DataAnnotations.ValidationResult IsValid(object value, System.ComponentModel.DataAnnotations.ValidationContext validationContext)
{
if (value!=null)
{
string fileName = value.ToString();
if (FileExists(fileName))
{
return new ValidationResult("Sorry but there is already an image with this name please rename your image");
}
else
{
return ValidationResult.Success;
}
}
else
{
return new ValidationResult("Please enter a name for your image");
}
}
Run Code Online (Sandbox Code Playgroud)
我已经像这样实现了它:
[ExistingFileName]
public string NameOfImage { get; set; }
Run Code Online (Sandbox Code Playgroud)
我确定这是一种在设置属性时定义错误消息的方法,如下所示:
[ExistingFileName(errormessage="Blah blah blah")]
public string NameOfImage { get; set; }
Run Code Online (Sandbox Code Playgroud)
但我不知道怎么样?任何帮助是极大的赞赏
使用正则表达式如何匹配字符串中的所有东西?这可能没有意义,但请继续阅读.
所以取词baby,例如匹配的一切,是不是一个b你会做这样的事情[^b],这将匹配a和y.很简单!但是,如果在这个字符串Ben sits on a bench中我能如何匹配那些不是ben我试图匹配的东西sits on a ch呢?
更好地匹配所有不是模式的东西?例如,1a2be3 匹配所有不是的东西number,letter,number,所以它会匹配字符串中的每个组合除外1a2?
我最近在一个网站上遇到了一个问题,网页上的样式确实搞砸了,但只在IE中.我的老板告诉我这可能是因为正在渲染的CSS Bundle包含来自不同目录的CSS文件,所以我检查了它.它类似于以下内容:
bundles.Add(new StyleBundle("~/path/subpath/all").Include(
"~/path/subpath/filename.css",
"~/path/subpath/filename1.css",
"~/path/subpath/filename2.css",
"~/path/subpath/filename3.css",
"~/path/subpath/anotherSubPath/filename.css",
"~/path/subpath/anotherSubPath/filename1.css",
"~/path/aDifferentSubPath/filename.css"));
Run Code Online (Sandbox Code Playgroud)
他说Bundling无法像这样工作,你必须只有Bundle中相同目录的文件,所以我把它们拆分成如下所示:
bundles.Add(new StyleBundle("~/path/subpath/all").Include(
"~/path/subpath/filename.css",
"~/path/subpath/filename1.css",
"~/path/subpath/filename2.css",
"~/path/subpath/filename3.css"));
bundles.Add(new StyleBundle("~/path/subpath/anotherSubPath/all").Include(
"~/path/subpath/anotherSubPath/filename.css",
"~/path/subpath/anotherSubPath/filename1.css"));
bundles.Add(new StyleBundle("~/path/aDifferentSubPath/all").Include(
"~/path/aDifferentSubPath/filename.css"));
Run Code Online (Sandbox Code Playgroud)
这在IE中解决了我们的问题.好的,现在我的问题:
我理解错误以及如何修复我只是想找到要修复的字段.让我从顶部开始.我每天运行一个计划任务,执行一个进程,在某些点运行一些运行插入语句的sql中的sprocs.不幸的是,在检查我的日志后,我收到了有问题的错误,因此我的sprocs无法正常工作.我可以将每个字段更新到更大的长度,这可能会修复它,但不是.是否有任何方法可以知道(没有手动检查,因为有很多字段和数千行)包含对于插入的字段来说太大的值的字段?
我正在尝试卸载最近安装的服务,我在命令行中运行它:
c:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil.exe /u "C:\inetpub\www
root\xxx\xxx\xxx.exe"
Run Code Online (Sandbox Code Playgroud)
但是我得到了这个:
The uninstall has completed.
An exception occurred while uninstalling. This exception will be ignored and the
uninstall will continue. However, the application might not be fully uninstalle
d after the uninstall is complete.
Run Code Online (Sandbox Code Playgroud)
还有这个:
Removing EventLog source xxx.
An exception occurred during the uninstallation of the System.Diagnostics.EventL
ogInstaller installer.
System.Security.SecurityException: Requested registry access is not allowed.
An exception occurred while uninstalling. This exception will be ignored and the
uninstall will continue. However, the application …Run Code Online (Sandbox Code Playgroud) 我目前正在修改Java se7认证,任何完成这些考试的人都知道他们使用的一些代码示例是多么荒谬.故意编写难以理解的代码.最近我看到很多代码写得像这样:
Object obj=new Animal();
Run Code Online (Sandbox Code Playgroud)
这提供了什么好处?我知道这是有效的代码,但这只是你在考试中不会使用大量代码的其中一项吗?如果不是何时以及为什么要这样做?
我有一个文本框
<asp:textbox runat="server" id="checkIn" ClientIDMode="Static" ReadOnly="true">
</asp:textbox>
Run Code Online (Sandbox Code Playgroud)
文本框中的文本通过Jquery DatePicker输入.在后面的一些代码中,我正在从这个文本框中获取文本.
string x=checkIn.Text;
Run Code Online (Sandbox Code Playgroud)
为什么我不能从文本框中提取输入的日期?我猜这是因为它是readonly,因为当我删除它有效吗?
谁能帮我?
我试图了解是否可以使用实体框架从数据库中获取一行而不返回所有数据。也许我误解了 EF 的工作方式,但我相信它类似于以下内容:
TBL1
Id | Name | Place
1 | Teressa Green | UK
2 | Robin Banks | Germany
3 | Liam Neeson | Canada
Run Code Online (Sandbox Code Playgroud)
如果我想要Robin BanksId 做类似的事情
context.tbl1.where(obj => obj.name = "Robin Banks")
Run Code Online (Sandbox Code Playgroud)
然而,据我所知,这是从表中获取所有数据,然后过滤到一行。有没有办法只将一行返回逻辑而不最初返回所有数据?
用一句话解决我的问题。当我只想要 1 时,我试图避免加载所有行。
我最近移动了公司,他们在SQL Server中做了一些我以前从未见过的事情.我习惯使用主键列作为int,在插入时递增,偶尔我看到guids的使用,但在这里他们使用两者,见下文.
PrimaryID | GUID | RestOfColumns
Run Code Online (Sandbox Code Playgroud)
我无法理解为什么?在问这个问题时,他们告诉我这是针对SQL注入的另一层保护.在存储过程中,他们使用guid查找主键ID然后再使用id,我个人看不到好处?
我的问题是:
编辑:
用法示例(伪代码):
在将其标记为重复之前,我已经看到了许多答案,例如“ 将IEnumerable转换为DataTable”,并试图通过创建扩展方法的方式进行类似的操作。我问我的问题,因为问题可能在其他地方。
从本质上讲,到目前为止,我有相当大的IEnumerable(大约16-17百万个项目),在使用扩展方法尝试转换为数据表之前,我并没有遇到任何问题:
/// <summary>
/// Converts IEnumberable to datatable. Mainly for use when using SQLBulkCopy/>
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="collection"></param>
/// <param name="customColumnOrder">Custom order for columns allows me to make sure that the order of columns will always be the same. Am open for suggestions for better ways to do this</param>
/// <returns></returns>
public static DataTable ToDataTable<T>(this IEnumerable<T> collection, List<Tuple<string, int, int>> customColumnOrder)
{
DataTable dt = new DataTable();
var type = collection.First().GetType();
foreach (var …Run Code Online (Sandbox Code Playgroud) c# ×6
.net ×3
asp.net ×2
sql ×2
sql-server ×2
asp.net-mvc ×1
bundle ×1
css ×1
datatable ×1
httpcontext ×1
java ×1
java-7 ×1
jquery ×1
linq ×1
regex ×1
service ×1
validation ×1